grav-plugin-facebook
grav-plugin-facebook copied to clipboard
Error with Events - Illegal string offset 'name'
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?
Thanks for the plugin and for your help.
I will get back to this probably on the next weekend.
I couldn't reproduce your problem but I added checks to that code. Check if release 1.7.0 works better for you.
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.
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'
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
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;
}
}
@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!