When the EntityBundle Condition Plugin evaluates the context, it assumes that the entity within is an actual entity object. But in some situations it seems to be only the entities id. My situation is:
- Created a page for taxonomy terms, having a variant that selects by using the EntityBundle Condition Plugin
- Added a custom view for reordering articles within that taxonomy term, that is displayed as an additional tab next to "view / edit / devel.." of a given taxonomy term
- When switching to the custom view, the system tries to render the breadcrums, which use the PathBasedBreadcrumbBuilder
- This Builder tries to evaluate the path to the "view" route of the taxonomy term
- That triggers the page / page variant and the EntityBundle Condition Plugin for selection to check access
- In this context of the condition plugin, the "taxonomy_term" is only the id, not the actual entity
=> Error: Call to a member function bundle() on string
Comment | File | Size | Author |
---|---|---|---|
#28 | 2785499-28.patch | 1.28 KB | Oscaner |
#21 | ctools_entity_bundle.patch | 1020 bytes | rockzhang |
#20 | ctools_entity_bundle-2785499-20.patch | 613 bytes | loze |
#12 | ctools_fix_condition_plugin_entity_bundle-2785499-12.patch | 1023 bytes | maxdev |
#2 | ctools-2785499-fix-entity-string.patch | 1.63 KB | perprogramming |
Comments
Comment #2
perprogramming CreditAttribution: perprogramming commentedComment #3
andypostComment #4
nguyenphanI tested okay. Thanks.
Comment #5
volegerthis patch works and help with the issue of
General Data Protection Regulation (GDPR) - Fields
submodule ofGeneral Data Protection Regulation (GDPR)
module.+1 for RTBC
Comment #6
BerdirThat seems like a workaround, whoever provides that context is doing it wrong, the value must be a loaded entity object.
Comment #7
joelpittetSetting to needs work for #6 because I agree, that seems like a workaround.
Comment #8
phjouI agree with @berdir and @joelpittet This patch is just a workaround.
I've encountered the same problem once on a project. It was some custom code that was unsetting the entity in the parameters of the route.
You probably should debug the error and find what module is causing your problems.
The patch should not stay too long on your project, only the time to find what is the real reason of your issue.
Comment #9
Dirst CreditAttribution: Dirst commentedHello, I found another issue related to this piece of code. When I have custom 404 page, and try to load taxonomy term page that doesn't exist (view overrided in page manager) it throws an error because $entity is empty. Something is related to the topic?
Comment #10
maxdev CreditAttribution: maxdev as a volunteer commentedThis is quite important issue.
If you are using Page manager's node_view this issue can be easily reproduced.
For example go to not existing node. If one of your node_view variants has selection criteria by EntityBundle or Content Type, then ctools plugin always throws fatal error:
This happens, because $this->getContextValue($this->bundleOf->id()) return string of nid (not existing node) instead of entity object.
Comment #11
maxdev CreditAttribution: maxdev at JYSK for JYSK commentedI found also core issue a bit related to current 1932810
There is initiative to move EntityBundle condition plugin to core. I tried patches from 1932810, but after this ctools plugin became not working.
So if you had functionality, where was used ctools plugin it will not work anymore.
I created transitional patch for ctools, which should fix fatal error, when context is not an entity object.
Comment #12
maxdev CreditAttribution: maxdev at JYSK for JYSK commentedOops, removed empty lines
Comment #13
michfuer CreditAttribution: michfuer at Mediacurrent commentedI'm seeing the same issue described in #10.
page_manager page for /node/{nid} with selection criteria to check for entity_bundle:node is a certain type.
Navigating to a non-existent nid, expecting a 404 response, but getting server error instead.
The patch in #12 helps, but than I'm seeing a similar error coming from /core/modules/node/src/Plugin/Condition/NodeType.php
because the /node/{nid} page has a variant using node_type plugin id for selection criteria.
Comment #14
shashank5563 CreditAttribution: shashank5563 commentedHello All,
After adding the given code my issue is resolved.
@@ -104,6 +105,11 @@ class EntityBundle extends ConditionPluginBase implements ConstraintConditionInt
}
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->getContextValue($this->bundleOf->id());
+
+ if (!$entity instanceof ContentEntityInterface) {
+ return true;
+ }
+
return !empty($this->configuration['bundles'][$entity->bundle()]);
}
Comment #15
BD3 CreditAttribution: BD3 commentedI can confirm that the patch in #12 fixed the issue for me when trying to duplicate Commerce Variations.
Comment #16
dewolfe001 CreditAttribution: dewolfe001 commentedshashank5563 - that fixed my issue! Thanks!
Comment #17
loze CreditAttribution: loze commentedI was getting this with a view that uses a commerce_product id in the path as an argment.
Patch in #12 fixes this for me.
Comment #18
loze CreditAttribution: loze commentedI spoke to soon.
While the patch in #12 does resolve this issue, it causes the pathauto checkbox not to appear on entity forms.
shashank5563'a comment in #14 looks like it got it working correctly.
Comment #19
shashank5563 CreditAttribution: shashank5563 commentedHi @loze,
I have tested my code with pathauto module and it is working fine can you create a patch for it.
Because, I am unable to create patch due to the some issue in my laptop.
Thanks in Advance
Comment #20
loze CreditAttribution: loze commentedhere's a patch that got it working for me with the latest dev verison.
Comment #21
rockzhang CreditAttribution: rockzhang commentedFix missing namespace for patch in #20
Comment #22
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot commentedComment #23
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot commentedComment #24
joelpittetThanks all! I've committed this to the latest dev release.
Comment #27
dubgeiser CreditAttribution: dubgeiser commentedBetween #12 and #14 the return value has gone from FALSE to TRUE... Is this intentional?
Because returning TRUE doesn't fix this at all on my end...
Comment #28
Oscaner CreditAttribution: Oscaner at CI&T commentedNo require for context, this condition will effect no-content pages.