When attempting to view a previous revision of a translated page using zurb_foundation 8.x-6.x-dev on Drupal 8.1.1 the following error is appearing:

Fatal error: Call to a member function bundle() on string in /var/www/drupalvm/docroot/themes/zurb_foundation/zurb_foundation.theme on line 259

Error is present when using sub-theme built from starterkit and using zurb_foundation as theme.

No error present when using "Bartik 8.1.1" or "Seven 8.1.1" theme.

Comments

rakugaki created an issue. See original summary.

bkhandruk’s picture

Status: Active » Needs review
StatusFileSize
new814 bytes

This error occurs because when you're trying to view node revision, variable $variables['node'], passed into template_preprocess_page, is not an object. It's a string within current node ID. So, to fix this error I've added a check whether the variable $variables['node'] is an object. And if it's not, then this object is loaded by ID.

tim_dj’s picture

Above patch will still fail if you try to view a revision of a non-existing node id.

Also I think the correct function to add this suggestion would be "zurb_foundation_theme_suggestions_page_alter"

samuel.mortenson’s picture

Priority: Normal » Major

This seems like an important bug to fix, I'm bumping the priority.

@tim_dj Can you explain why array_splice is being used here instead of the previous operation ($suggestions[] = ...)?

tim_dj’s picture

Otherwise the sequence of suggestions would be out of order:

array_splice

Array
(
    [0] => page__node
    [1] => page__node__product
    [2] => page__node__%
    [3] => page__node__10657
)

$suggestions[]

Array
(
    [0] => page__node
    [1] => page__node__%
    [2] => page__node__10657
    [3] => page__node__product
)

samuel.mortenson’s picture

Status: Needs review » Fixed

Thank you @tim_dj! Committed to the 6 and 5 branches.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ressa’s picture

This is not related to the ZURB foundation theme, but I am posting this for others who find this issue, looking for help with PHP Fatal error: Call to a member function bundle() on string:

I just want to add you have to careful with this - I just got stung where \Drupal::routeMatch()->getParameter('node'); will return an array of 1 item (the node id) on node revision delete pages, so if you calling a method on what you assume to be an object you will get a fatal error like "Fatal error: Call to a member function getType() on string". – Jeff Burnz Aug 10 at 1:13

To be sure you have really a node you can use "if ($node instanceof \Drupal\node\NodeInterface) " condition. (see drupal.org/docs/8/api/entity-api/working-with-the-entity-api‌​) – tdd Nov 28 at 7:48

From: http://drupal.stackexchange.com/questions/145823/how-do-i-get-the-curren...

ressa’s picture

I couldn't get the suggestions on the "Working with the Entity API" page to work, but making sure that revisions wasn't present in the URL seemed to do the trick:

if (($node = \Drupal::routeMatch()->getParameter('node')) && (strpos($_SERVER['REQUEST_URI'], "revisions") == false)) {
  ...
}
guybrush threepwood’s picture

@ressa, Thank you so much! This saved me.