Problem/Motivation
When using page manager to override a node view page, there's a fatal error on adding a content type condition as variant selection criteria:
Error: Call to undefined method Drupal\Core\Plugin\Context\EntityContextDefinition::setConstraint() in /var/www/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php on line 273 #0 /var/www/modules/ctools/src/Plugin/Condition/NodeType.php(37): Drupal\Core\Plugin\Context\ContextDefinition->setConstraints(Array)
#1 /var/www/modules/ctools/src/Plugin/Condition/NodeType.php(17): Drupal\ctools\Plugin\Condition\NodeType->removeConstraints(Array)
#2 /var/www/modules/ctools/src/Form/ConditionConfigure.php(117): Drupal\ctools\Plugin\Condition\NodeType->applyConstraints(Array)
#3 [internal function]: Drupal\ctools\Form\ConditionConfigure->submitForm(Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array)
#5 /var/www/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#6 /var/www/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/core/lib/Drupal/Core/Form/FormBuilder.php(318): Drupal\Core\Form\FormBuilder->processForm('ctools_conditio...', Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('ctools_conditio...', Object(Drupal\Core\Form\FormState))
#9 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#10 /var/www/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
It looks like there's a simple mistake in \Drupal\Core\Plugin\Context\ContextDefinition::setConstraints()
which tries to proxy the call to \Drupal\Core\Plugin\Context\EntityContextDefinition::setConstraint()
instead of ::setConstraints($constraints)
(added in #2986033: [regression] The BC layer for EntityContextDefinition in ContextDefinition is incomplete).
Proposed resolution
Proxy to the correct method - \Drupal\Core\Plugin\Context\EntityContextDefinition::setConstraints()
.
Remaining tasks
- Needs review by someone who understands the BC layer!
Original report by Siavash
Hello,
I'm having some issues with a freshly installed Drupal site with Panels + Page Manager installed. Tried with both latest release and dev version.
I'm trying to create a variation for the node path for a specific content type. But when I go to save the content types or bundle types I get an ajax error and I'm unable to save the settings. (See screenshot)
PHP log ha an error:
Error: Call to undefined method Drupal\Core\Plugin\Context\EntityContextDefinition::setConstraint() in Drupal\Core\Plugin\Context\ContextDefinition->setConstraints() (line 273 of .../web/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php) #0
Would appreciate any support, thanks!
Comment | File | Size | Author |
---|---|---|---|
#15 | drupal-contextdefinition_bc_fix-2998462-15-D8.patch | 10.55 KB | AndyF |
Screenshot 2018-09-10 04.31.07.png | 341.08 KB | Siavash |
Comments
Comment #2
millionleaves CreditAttribution: millionleaves as a volunteer and commentedI have the same issue on a site that I recently upgraded from 8.5.6 to 8.6.0. Before upgrading, I was able to add Content Type as a condition for variant selection. Since upgrading, I can't.
I am able to add other condition types, e.g. Request Path, without any issues.
Comment #3
LeGront CreditAttribution: LeGront commentedI have the same issue after update from 8.5.6 to 8.6.1
Comment #4
millionleaves CreditAttribution: millionleaves as a volunteer and commentedI'm marking this as critical since it appears that this issue is reproducible and is introduced when upgrading to 8.6.x. It represents a significant degradation of key functionality.
The only workarounds I can currently see are:
Neither of these workarounds meet all use cases that can be met by setting Content Type as a variant-level condition.
Comment #5
Baysaa CreditAttribution: Baysaa at Fabb commentedLinking to core issue with patch.
Sounds like this was originally caused by #2986033: [regression] The BC layer for EntityContextDefinition in ContextDefinition is incomplete
Comment #6
AndyF CreditAttribution: AndyF at Fabb commentedThanks @Baysaa, I've marked that issue as duplicate (I don't think I should've created a new one).
I'm tentatively moving this to core, and bumping down the priority, at most it's major imho. Tracing through, the issue seems to come from a call to
\Drupal\Core\Plugin\Context\EntityContextDefinition::setConstraint()
from\Drupal\Core\Plugin\Context\ContextDefinition::setConstraints()
. It involves a BC layer that was added in #2986033: [regression] The BC layer for EntityContextDefinition in ContextDefinition is incomplete, and it looks like it's a simple mistake in the name of the method to call on the BC layer. Certainly changing the call tosetConstraints($constraints)
seems to fix the page manager issue for me (patch attached). If someone who knows can confirm it's ok, I'm happy to look at adding a regression test.Thanks!
Comment #7
Baysaa CreditAttribution: Baysaa at Fabb commentedPatch in #6 works for me. Tested by adding all conditions that come out of the box on a clean install.
Comment #8
Baysaa CreditAttribution: Baysaa as a volunteer commentedComment #9
Baysaa CreditAttribution: Baysaa at Fabb commentedRe-uploading patch to trigger testbot to run against drupal and not page_manager.
Comment #10
millionleaves CreditAttribution: millionleaves as a volunteer and commentedThanks. Applying the patch in #9 has resolved the issue for me, in that I can now add Content Type as a selection criteria for a variant.
Comment #11
Baysaa CreditAttribution: Baysaa at Fabb commentedJust removing an old patch from display.
Comment #12
Pasquallesimple logical fix..
Comment #13
markdcThanks for the patch. #9 works.
Comment #14
tim.plunkettThis was introduced by #2986033: [regression] The BC layer for EntityContextDefinition in ContextDefinition is incomplete, itself a regression, but included a test.
This issue should expand that test or include a new one.
Comment #15
AndyF CreditAttribution: AndyF at Fabb commentedHere's a first pass at some tests, which I did in collaboration with @Baysaa: feedback welcome. It doesn't touch the existing fix.
Thanks!
Comment #17
crafter CreditAttribution: crafter as a volunteer commentedThis problem is still there.
Comment #18
Patrick Ryan CreditAttribution: Patrick Ryan commented+1 #15 works as expected
Comment #19
tim.plunkettLooks ready for RTBC except the deprecations say 8.6 and should be 8.7.
Comment #20
AndyF CreditAttribution: AndyF at Fabb commentedThanks for your time!
I think it should be 8.6 here - the deprecation has already been added (see 099f414) and we're just testing it. Tentatively setting back to needs review, please let me know if I've missed something.
Comment #21
tim.plunkettOh, right you are! Thanks :)
Comment #22
markdc#15 is working for me. Thanks for the relatively quick fix.
Comment #23
alexpottCreditting @tim.plunkett, @fatmarker and @millionleaves for patch review and manual testing.
Committed 14606cc and bbcfd53938 pushed to 8.7.x and 8.6.x. Thanks!
Comment #26
superlolo95 CreditAttribution: superlolo95 commented#15 is working for me.
Thanks