Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Events - Illegal string offset 'name' #36

Open
MacKisco opened this issue Oct 22, 2017 · 7 comments
Open

Error with Events - Illegal string offset 'name' #36

MacKisco opened this issue Oct 22, 2017 · 7 comments

Comments

@MacKisco
Copy link

Hello,

I'm trying to use the Events on my site and have the following error:

An exception has been thrown during the rendering of a template ("Illegal string offset 'name'").
Line 275 of Facebook.php
$r[$start_at]['place']['name'] = $val->place->name;

Here is the Facebook page id for which I'm trying to get the events: 329002043817618

If I comment the lines 275 and 277, then the events are displayed on my page.
Do you know what can be the problem?

eventserror

Thanks for the plugin and for your help.

@mikahanninen
Copy link
Owner

I will get back to this probably on the next weekend.

@mikahanninen
Copy link
Owner

I couldn't reproduce your problem but I added checks to that code. Check if release 1.7.0 works better for you.

@MacKisco
Copy link
Author

I've got the same error with 1.7.0 after cache clean.

I was able to make it work with the following change (from line 175):

if (property_exists($val, 'place')) { $r[$start_at]['place_name'] = $val->place->name; if (property_exists($val->place, 'location')) { $r[$start_at]['place_location'] = $val->place->location; } }

And of course I used "place_name" in my template facebook.event.html.twig.

@mikahanninen
Copy link
Owner

mikahanninen commented Nov 1, 2017

I would like to understand the reason of this error... it is probably initialization was missing for those 2 keys. Could you try clean plugin code and just add these 2 lines. I can't understand why I am not getting error you are getting - probably something to do with PHP versions, module versions etc..

            $r[$start_at]['event_link'] = $val->id;
            $r[$start_at]['name'] = nl2br($val->name);
            $r[$start_at]['place'] = '';
            $r[$start_at]['description'] = '';
            $r[$start_at]['cover'] = '';
            $r[$start_at]['place']['name'] = '';    // INIT 'name'
            $r[$start_at]['place']['location'] = ''; // INIT 'location'

@MacKisco
Copy link
Author

MacKisco commented Nov 4, 2017

This solution doesn't work either.
But, if I just comment the following line, it works (without your two new INIT lines):
$r[$start_at]['place'] = '';

Maybe because it's initialized as a String and then we try to put an array inside...
So if it still works in your version, it's a good solution good for me. Thank you

@ghost
Copy link

ghost commented Nov 10, 2017

I had the same issue when I first starting using this. I believe it's caused by not having a place specified for the event. For example, if you're doing events at various locations (like a band or speaker) you'll always add the place. In my case I'm trying to show events happening at a single location (a bar or restaurant), they never need to add a location because all their events happen at their establishment. I'm not sure if it's the setting itself, or if it's because they're set to be the same - but it's something with that particular scenario.

Commenting out the place call in facebook.php solves it - code below. I'm looking at this thread today because I'm updating and I have to update this code every time I update the plugin. Even if this doesn't have a quick solution, Is it possible to override facebook.php? Just curious, everything else works beautifully, great job, love this plugin.

Comment out lines 273 to 285:

if (property_exists($val, 'place')) {
    if (property_exists($val->place, 'name')) {
        $r[$start_at]['place']['name'] = $val->place->name;
    }
    if (property_exists($val->place, 'location')) {
        $city = '';
        $country = '';
        if (property_exists($val->place->location, 'city')) $city = $val->place->location->city;
        if (property_exists($val->place->location, 'country')) $country = $val->place->location->country;
        $r[$start_at]['place']['location'] = $city.' '.$country;
    }
}   

@bzx
Copy link

bzx commented Feb 16, 2018

@cpfeifer Had the same exact issue, even though the events I was fetching do have location set (to the venue they're happening in). I commented the lines from your post and it works perfectly. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants