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

Call to a member function label() on null #28

Closed
laryn opened this issue Jun 18, 2020 · 16 comments
Closed

Call to a member function label() on null #28

laryn opened this issue Jun 18, 2020 · 16 comments

Comments

@laryn
Copy link
Member

laryn commented Jun 18, 2020

I upgraded a few modules on a dev site and started getting a maintenance screen with this error: Call to a member function label() on null.

I tracked it down to entity_plus.theme.inc where it's trying to set the $entity variable, but in at least one case that was apparently null. Does that make any sense to you @hosef? For the moment I'm just blocking the whole section in template_preprocess_entity_plus with a if (!empty($variables['elements']['#entity'])) {...

@laryn
Copy link
Member Author

laryn commented Jun 30, 2020

This particular site seems to have an issue that I'll need to troubleshoot -- I'm guessing this is related:
backdrop-contrib/paragraphs#14
(Edit: not related)

That said, it's possible it's something particular with this site. Any ideas more than welcome however...

@laryn
Copy link
Member Author

laryn commented Jul 24, 2020

On this line:

  if (!empty($variables['elements']['#entity'])) {
    $entity = $variables['elements']['#entity'];
  }
  else {
    return;
  }

@jenlampton
Copy link
Member

jenlampton commented Sep 12, 2021

I'm having the same problem after installing paragraphs, and attempting to override paragraphs-item.tpl.php, so I don't think it's specific to your site @laryn.

I also noticed that for every paragraphs item, the paragraphs_item template is being applied twice. One time it only contains the class entity_plus (when it is stashed into the #children key of the renderable, with #printed is set to TRUE) so I wonder if entity_plus might be doing the rendering there?

See related: backdrop-contrib/paragraphs#91

@jenlampton
Copy link
Member

The ParagraphsItem view() method calls entity_get_controller($this->entityType())->view which in this case, is EntityPlusController(). The view() method there contains this code comment:

// If the entity type provides an implementation, use this instead the
// generic one.
// @see template_preprocess_entity()

I think maybe this is the problem. Not only has this documentation not been updated (I'm sure that was supposed to say template_preprocess_entity_plus() instead) but if it's attempting to add a theme hook suggestion that's not a derivative entity_plus.tpl.php, it's too late to do so here, because all the variables will have been already preprocessed as though they were intended for entity_plus, and not for the actual template being used.

I'm going to fiddle with this and see if changing the #theme here solves the problem. If not, I may be barking up the wrong tree :)

@jenlampton
Copy link
Member

jenlampton commented Sep 12, 2021

Well, progress? If I change the theme hook here, the page seems to render correctly (with my template only applied once). But I don't know how to check the theme registry to see if a specific function is provided, so I ended up with this mess:

      // If the entity type provides its own themed output, use that instead.
        // @todo find out how to check the registry without calling this way.
      $themes = list_themes();
      $theme_registry = _theme_load_registry($themes['basis']); // Gah!
      if (array_key_exists($this->entityType, $theme_registry)) {
        $build['#theme'] = $this->entityType;
      }

...as well as some PHP errors. I'm going to sort through the errors and see if it sheds any other light.

@jenlampton
Copy link
Member

The PHP errors were helpful :) I think I found a fix for backdrop-contrib/paragraphs#91.

I'm having the same problem after installing paragraphs, and attempting to override paragraphs-item.tpl.php, so I don't think it's specific to your site @laryn.

I suspect this issue may be specific to all sites with Paragraphs. Since implementing the fix above I haven't encountered this problem anymore. If someone else can confirm, maybe we can close this?

@laryn
Copy link
Member Author

laryn commented Sep 13, 2021

Thank you @jenlampton -- the preliminary testing in the Paragraphs thread you linked looks promising enough that I'll close this one here. Thanks so much!

@laryn laryn closed this as completed Sep 13, 2021
@laryn
Copy link
Member Author

laryn commented Oct 13, 2021

Reopening as the fix in the Paragraphs queue breaks some preprocessing functionality.

@hosef do you have any insight on how this might relate in Entity Plus's implementation where Paragraphs items are getting rendered twice? From @jenlampton in the Paragraphs thread:

I think the problem was that we were telling the paragraph item to use the paragraph_item template as a theme wrapper, but it already renders using that template due to entity_plus changing the theme_hook_suggestions in template_preprocess_entity_plus().

I don't like how entity_plus is both providing theme output, and then switching the output source to use something else, but that seems to be as intended. In a perfect world all it would do is render() and allow whatever provided the thing to specify it's own output. I didn't try to fix it though, that seems hard :)

@laryn
Copy link
Member Author

laryn commented Dec 4, 2021

@jenlampton mentioned the view method above. @herbdool just mentioned that separately. Could this relate? I haven’t had time to dig but wanted to make the connection in a comment just in case:

backdrop-contrib/paragraphs#106 (comment)

@argiepiano
Copy link
Collaborator

@laryn I'm looking into this issue, but I'm not clear how to reproduce the error. I installed paragraphs and it's working fine so far. Can you give me a clue on how to reproduce it?

@laryn
Copy link
Member Author

laryn commented Dec 4, 2021

Add a template override for paragraphs-item.tpl.php in your theme, even if just copying the one from the paragraphs module.

@herbdool
Copy link
Contributor

herbdool commented Dec 4, 2021

@laryn maybe try buildContent method instead of view? Entity Plus would not add its own theme suggestions I think. Just spitballing.

@argiepiano
Copy link
Collaborator

I think you are aware of this, but looking at the themed output, it looks like there is some theme nesting going on. Compare to D7's output below.

Currently Drupal 7 Paragraphs does not have a template_preprocess_paragraphs_item function, while Backdrop does. In Drupal template_preprocess_entity is called once per paragraph instance. Backdrop calls it twice, and calls template_preprocess_paragraphs_item as well.

I don't know what all of this means, but I'll sleep over it. I'll keep looking into this tomorrow...

BACKDROP'S OUTPUT
Screen Shot 2021-12-03 at 10 12 52 PM

DRUPAL'S OUTUT
Screen Shot 2021-12-03 at 10 14 02 PM

@argiepiano
Copy link
Collaborator

argiepiano commented Dec 4, 2021

@laryn , after moving the paragraphs-item.tpl.php file into the themes folder, I'm can't reproduce the error reported here. I left the tpl file intact and also verified that it's being called. Can you let me know if you have modified the tpl file (or any of the parent tpl files like node.tpl.php or paragraphs-items.tpl.php? For example, are you doing some custom printing of a sub-element of the $content array in any of those parent tpls?

HOWEVER, after quick inspection, I can confirm that the current version of Paragraph is double-printing (calling twice or three times per field) the paragraphs-item.tpl.php, invoked both by entity_plus and paragraphs, each time with a different $content. This double-calling causes the troubling nesting of divs with the same classes that you see in the images I posted above.

I discovered that @jenlampton had reported exactly this markup problem in backdrop-contrib/paragraphs#91 (comment) and she provided a PR that actually solves this. I will continue this conversation there.

In the meantime, if you could let me know about my tpl modifications questions I typed at the top of this comment I could test and see if I'm able to reproduce the error of this issue.

@argiepiano
Copy link
Collaborator

argiepiano commented Dec 4, 2021

@laryn I was able to reproduce the error reported here by enabling Modal Administration for Paragraphs, and by using a template file in the theme's folder rather than the one provided by the the module. So, that's progress.

I have a hunch that this (as well as backdrop-contrib/paragraphs#91) is all caused by the double call of template file. I don't think this is a bug in Entity Plus, but rather an issue produced by that double call.

The Paragraphs PR backdrop-contrib/paragraphs#92 eliminated the double invocation of the template and produced a more sensible html markup output, BUT it interfered with the Modal Administration. I believe you re-added the #theme_wrappers line in Paragraphs here to solve the Modal issue, according to the comments you inserted above that line.

I'm going to try to focus on making the Paragraph's Modal Administration work without re-adding that #theme_wrappers line. For starters, there is an issue with how classes are applied in paragraphs-item.tpl.php for which I'll create a PR over there.

I'll keep you posted on any progress.

@argiepiano
Copy link
Collaborator

This issue was the result of issues with Paragraphs that have been resolved. See backdrop-contrib/paragraphs#110. Closing.

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

4 participants