Closed (fixed)
Project:
Entity Pager
Version:
8.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Feb 2020 at 17:54 UTC
Updated:
9 Oct 2021 at 14:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
Tristanwellz commentedComment #3
bmunslow commentedI'm experiencing the same issue:
Patch #1 by @Tristanwellz didn't fix the error in my case.
After all, there are chances that $entity can't be retrieved in this final check either:
Which is what happens in my case, when entities are rendered in a preprocess query for entities indexed by Search API.
In short, I think it's necessary to add a final check before we return the $entity:
Attached patch with this solution fixes the problem for me.
Comment #4
nace_fr commentedHi. I also have the same issue and I tested patch from #3. It applied successfully and solved the issue. Logs are clear. Changing status to RTBC.
Comment #5
wongjn commentedThank you for the contribution! I would like some tests to cover the case where this error shows up; can a test be added? Or if not, if someone can tell me how to recreate the error, I can look at writing the test myself.
Comment #6
chrisckAnother example of creating the error where the entity variable can't be retrieved is in layout builder. For example, I have a layout for node type Article.
In layout builder, there is no entity variable as we're not viewing an entity/node. Entity pager does not know where we are in the pagination. So we get the following errors:
Notice: Undefined variable: entity in Drupal\entity_pager\EntityPager->getEntity() (line 119 of modules\contrib\entity_pager\src\EntityPager.php).
Notice: Undefined variable: entity in Drupal\entity_pager\EntityPager->getEntity() (line 123 of modules\contrib\entity_pager\src\EntityPager.php).
I've tested patch in #3 against 1.x-dev today and it is working. No more undefined variable errors.
Comment #7
chrisck@Wongjn Can we set this to RTBC? I've outlined an example of how to recreate the error. The patch is a fairly simple one.
Comment #8
wongjn commentedStill needs tests please! If no one does write any, I can have a look soon.
Comment #9
chrisckComment #12
wongjn commentedComment #13
wongjn commented