While debugging the Wizard API for Page Manager, I found that ContextConfigure.php has the following code at the submit method:
if (strpos($context_definition->getDataType(), 'entity:') === 0) {
list(, $entity_type) = explode(':', $context_definition->getDataType());
if (is_numeric($form_state->getValue('context_value'))) {
$value = \Drupal::entityTypeManager()->getStorage($entity_type)->load($form_state->getValue('context_value'));
}
}
The line is_numeric() evaluates to false when you want to add a context such as Action, which has entity ids such as comment_publish_action. This causes the following error when the context is added because the value is required:
[Wed Mar 30 14:08:00.395367 2016] [:error] [pid 1700] [client 127.0.0.1:46308] Uncaught PHP Exception Drupal\\Component\\Plugin\\Exception\\ContextException: "The 'entity:action' context is required and not present." at /var/www/drupal8/core/lib/Drupal/Core/Plugin/Context/Context.php line 76, referer: http://d8.local/admin/structure/page_manager/manage/asdfaasdfd/page_variant__asdfaasdfd-block_display-0__contexts
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | ctools-non_numeric_context_id-2696819.patch | 843 bytes | fskreuz |
Issue fork ctools-2696819
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
juampynr commentedHere is a patch that fixes it. I did not find any Web tests to adjust in order to prove it. Should we create a new test that manages contexts?
Comment #3
sunset_bill commentedPatch applies and fixes the issue I was seeing that was preventing me from adding contexts.
Comment #4
sunset_bill commentedComment #5
japerryhmm so while the bug is totally legit, I think the patch is concerning. There was probably? good reason for us to check for that. We might need to add some other checks to make sure the input is proper.
And yup, we also need a test.
Comment #6
dcam commentedI just ran into this bug while trying to add contexts in Page Manager. This bug essentially makes it impossible to add contexts for any config entity since their IDs are usually not (never?) numeric. I came up with the same fix as in #2.
I can't guess as to why it was written this way, but I'll try to remember to ask @EclipseGc the next time I see him.
Comment #7
karolus commentedJust testing this in Drupal 8.5.0 running on PHP 7.0.
#2 is working fine for me. What needs to be done to add this change?
Comment #8
andypostPatch adds proper injection of ETM service & clean-ups docs for affected lines
@japerry this class is abstract and only page manager implements this forms:
-
\Drupal\page_manager_ui\Form\StaticContextConfigure-
\Drupal\page_manager_ui\Form\AddVariantStaticContextConfigureCan you point how to write test for this form? should it live in ctools or better add test for page manager?
Comment #9
karolus commented@andypost @japerry Is there anything I can do to help? Most of my skills are design/front-end, but if given some guidance can get things started.
Comment #11
jonathan1055 commentedThe test fails are unrelated to this patch. Setting to 'Needs Review'
Comment #12
andypostBasically it needs a simple test case to add a coverage for the form, but I found forms in page manager module only
So for me it is not clear how test could be added here for abstract class
Comment #13
karolus commented@andypost I have an example using Panels Everywhere.
This screenshot shows a successful context set for using a particular layout with Panels Everywhere.
Comment #14
jmuzz commentedEdit: My bad something else is going on in my case.
Comment #15
fawad ali commentedIts work for me the context is added but now the tokens are not available to add the panel page. As in #13 the context is added but now the fields or the full form of the basic page content type is not available.
Comment #17
artematem commentedUpdate patch for 8.x-3.1 release
Comment #18
shubham.prakash commentedHope this will pass the test cases.
Comment #19
jonathan1055 commentedJust for the record, seems like the majority of the code added between patch #2 and patch #8 is already committed. The patch in #18 is the same as in #17 and that essentially matches the previous actual change, so that's all good.
However, from the comments in #2 and #5 we need a test case to cover this, before it is committed. Can we use an example from Panels Everywhere as per #13?
Comment #21
mrP commentedI rerolled patch #18 here -- https://git.drupalcode.org/issue/ctools-2696819/-/commit/0585fc2007c481a...
Comment #22
lamp5This issue is fixed in the latest release.
Comment #23
jonathan1055 commented@lamp5, is there really nothing more to do? I thought we needed test coverage, see comments #2, #5, #12, #13 and #19
Comment #24
jonathan1055 commentedActually I have just checked in 8.x-3.5 (released 16 April 2021) and the single change from patch in #2 has not been included. We still have
So it is still checking that the context_value is numeric. The dependency injection of EntityTypeManager was done in #3013146: Drupal dependency injection so everything else from patch #8 is included in 8.x-3.5. But the important bit about not checking for numeric has not been removed.
Comment #25
andypostComment #26
jonathan1055 commentedRe-rolled #18 which has the required code change and added the function doc block. Still no tests added.
Comment #27
andypost@jonathan1055 thank you
Comment #28
jeroen dost commentedThe patch in #26 doesn't seem to do the work anymore after security update to v3.6. I now get this error (again):
Downgrading to v3.5 solves the problem. What was changed in 3.6 and should be added to the patch (or in fact included in the next release)?
Comment #29
david.fcondezo commented@Jeroen Dost Did you manage to find a fix for the problem after 3.6?
Comment #30
fskreuz commentedUpdated patch against 3.x, which is currently at 3.8.
Comment #31
japerryBefore this can get committed, I'd want to see some tests.
Comment #32
jonathan1055 commentedWas there a reason for patch #30 having the docblock removed that was in patch #26?
Comment #33
fskreuz commented@jonathan1055 The re-roll was specifically meant to remove it because https://www.drupal.org/project/ctools/issues/3293702 added the docblock in 3.8 and the patch wasn't applying. It's best practice to keep patches/commits specifically about the thing it's fixing to reduce the chance of unnecessary merge conflicts.
Comment #34
jonathan1055 commentedThanks @fskreuz, yes of course, its best to keep patches focussed.