It seems like there is an error with the context creation for the routing in this module.
I have a module that is trying to generate an url to the page with the view_mode_page route:
$url = new Url(
'view_mode_page.display_entity',
[
'view_mode' => 'apply',
'entity_type' => 'node',
'entity_id' => $node->id()
]
);
But i get the following error:
Drupal\Component\Plugin\Exception\ContextException: The context is not a valid context. in Drupal\Core\Executable\ExecutablePluginBase->getContextDefinition() (line 184 of core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php).
Drupal\Core\Executable\ExecutablePluginBase->getContext() (Line: 116)
Drupal\Core\Executable\ExecutablePluginBase->getContextValue() (Line: 91)
Drupal\Core\Entity\Plugin\Condition\EntityBundle->evaluate() (Line: 77)
Drupal\Core\Condition\ConditionManager->execute() (Line: 84)
Drupal\Core\Condition\ConditionPluginBase->execute() (Line: 412)
Drupal\view_mode_page\Entity\ViewmodepagePattern->applies() (Line: 146)
Drupal\view_mode_page\PathProcessor\DynamicPathProcessor->processOutbound() (Line: 108)
Drupal\Core\PathProcessor\PathProcessorManager->processOutbound() (Line: 388)
I have checked and the view mode exists. This might be an issue with only newer drupal versions i only got this issue after updating core from 9.3.3 to 9.4.4
It seems to break on the check `$definition instanceof ContextAwarePluginDefinitionInterface` in the ContextAwarePluginTrait::getContextDefinition line 176.
Comments
Comment #2
wrg20 commented+1
Comment #3
robertmartin1961 commentedDisabling the "pathauto" module resolved the issue for me, however it remains an issue that needs addressing as that is merely a workaround. In addition, I have the "domain" module enabled, which is known to cause issues with other modules that require workarounds.
Comment #4
maplinx commented@robertmartin1961, thank you!
Thanks also @hikkypo for your post.
Well I thought I was doing something wrong! Was installing a new site and all looked good until I wrote a welcome page and 48hrs after, its problem solving mode! Despite figuring out the problem from the error message ("Drupal\Component\Plugin\Exception\ContextException: The context is not a valid context. in Drupal\Core\Executable\ExecutablePluginBase->getContextDefinition() (line 184 of /home/ndagr/public_html/core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php")., and uninstalling the usual culprits modules, I was no near solving it.
I understand this file or part thereof would be depreciated in dv10.
Comment #7
daveianoI opened a merge request for this.
The error seems to be related to this change record: https://www.drupal.org/node/3120980
If you visit the overview page (/admin/config/search/view-mode-page), the 'content type' condition is marked as deprecated.
The MR fixes this and also an other deprecation: The usage of
ContextAwarePluginBaseinsrc/Plugin/view_mode_page/AliasType/EntityAliasTypeBase.php.Note: You need to re-create your view-mode pages to get this working. We should implement an update hook to replace the deprecated condition.
Comment #8
mistergroove commented+1
Also I noted that if I use view mode page I get the error when viewing the page and also if I try to create a URL to that page.
So if my node bundle view mode page has the pattern:
/%/fulltextAnd I try to create a link to the view mode page using the following code:
$fulltexturl = Url::fromUri('internal:' . $nodeurl->toString() . '/fulltext');I get the same error:
Uncaught PHP Exception Drupal\\Component\\Plugin\\Exception\\ContextException: "The context is not a valid context." at /www/dev/project-xxx/web/core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php line 184Comment #9
glynster commented@daveiano thanks so much for the update and fix. I just grabbed this update and created a patch out of it as we have no idea how long it will take for the merge request to occur. Works on 2 production sites, provided you recreate the modes again.
Comment #10
mistergroove commented@daveiano merge works great. Thanks for the patch @glynster but looks like it's missing the changes to src/Plugin/view_mode_page/AliasType/EntityAliasTypeBase.php.
As per: https://git.drupalcode.org/project/view_mode_page/-/merge_requests/3/diffs
Are these required? Apologies if i've misunderstood.
Comment #11
glynster commented@mistergroove on my end just with the patch things were sorted and we needed a quick fix for 2 production sites. I have gone ahead and included the other file in the patch to be more complete.
Comment #12
mistergroove commentedExcellent. Thanks so much @glynster.
Comment #13
daveiano@mistergroove The changes to src/Plugin/view_mode_page/AliasType/EntityAliasTypeBase.php are not needed to fix the issue. But these are Deprecations which will lead to problems in Drupal 10 and they are in the same context as this issue. So I thought I add these changes to the patch.
Sorry, I am just curious, why are you creating patch files manually? There is a "plain diff" link in the issue fork section!?
Comment #14
glynster commented@daveiano I had no idea you could do that. Thanks for the tip, I always thought it had to be a .patch.
https://git.drupalcode.org/project/view_mode_page/-/merge_requests/3.diff
Comment #15
peter pulsifer commentedSee also https://www.drupal.org/project/ctools/issues/3300682
Comment #16
daveianoComment #17
loopy1492 commentedJust adding a static patch after @daveiano's work above...
Comment #18
loopy1492 commentedFor some reason I keep uploading patches that start with a space in the file name.
Comment #19
coaston commented#18 resolved issues in D10.
Thank you. You have saved my day!
Comment #20
anybodyJust ran into the same issue. RTBC for #18
See similar issues: #3266631: Drupal 10 compatibility, require Drupal 9.3, #3351193: Class "Drupal\Core\Plugin\ContextAwarePluginBase This class has been deleted in version 10
Comment #21
anybodyAny maintainer here to merge this and tag a new 4.x release, as 4.x isn't really D10 compatible currently.
Comment #22
anybodyComment #23
andysipple commentedGetting the following error when trying to config import into a D10 site. Patch #18 is not working for me.
Turns out the config that it was trying to import the ID is wrong for D10.
Does not work id: 'node_type' works: id: 'entity_bundle:node'
Comment #24
nkraftThe patch in #18 PLUS the config update in #23 from AndySimple worked for me!
1) I applied patch #18 in composer.json and then by running composer update
2) Then went into my config sync folder, searched for: node_type
3) And then changed all instances related to view_mode_page from:
node_type
to
entity_bundle:node
then ran: drush cim
to import the manually modified config files
then
drush cr (as you do)
And voila! My view mode pages are back and working correctly! Thanks all, you saved my day, getting ready to take D10 live hopefully tomorrow. Cheers to you all.
Comment #25
stijndThe combination of #18 and #23 also worked for me. Perfectly explained by @nkraft!
Comment #26
pianomansam commentedChanging the status back to needs work as there are unresolved questions on the merge request. Further, the merge request doesn't do anything to solve the issue raised in #23. The fix in #23 is still a manual fix that should be taken care of programmatically with a migration/update.
Comment #27
jschref commentedWith a fresh install on D10 (not an upgrade from D9), patch #18 worked like a charm for me. Also fixed/is the root of this bad AJAX call:
https://www.drupal.org/project/view_mode_page/issues/3414818#comment-155...
Comment #28
rcodinaThe patch #18 works like a charm but the MR patch doesn't apply.
Comment #30
arlina commentedUpdated PR to be compatible with latest release 4.0.3, as it already addresses the deprecation issues.
Comment #31
btully commentedThe latest patch #18 fails to apply when using version 4.0.3 of the module through composer require.
Comment #32
pearls commentedI saw same issue as mentioned in #31. Patch #18 fails.
MR!3 ( #29) is applied but now other problems.
When creating a new pattern it shows
For existing patterns, I see the error mentioned in the screenshot below.

Versions: Drupal version 10.4.1 Viev mode page: 4.0.3
Comment #33
kleve commentedLooks like the 4.0.3 version includes the patch code. Maybe that is why you get `Could not apply patch` @btully.
Simply remove the patch should remove the error.
Comment #34
papagrandeIf this issue is indeed fixed, can we get a link to the issue and/or commit that updated the code?
Then we can mark this issue as "Closed (duplicate)" or "Closed (outdated)".
Comment #35
raphaelbertrand commentedThe issue is not yet fully fixed in 4.0.3, whithout patch or MR applied
I don't have time to investigate more on this issue now but maybe the work on related issues "#3318559: Replace use of node_type condition" and " #3356400: Drupal 10 compatibility" may help to finish to solve this one, mainly the part on /src/Form/PatternEditForm.php file.
Comment #36
raphaelbertrand commentedMaybe the commit that updated the code is in #3435378 Automated Drupal 11 compatibility fixes for view_mode_page ?
Comment #37
edmoreta commentedPosting the MR changes as a patch here. It is compatible with v4.0.3
Comment #38
raphaelbertrand commentedGood idea it help to see what remain in the MR.
Maybe switch back to "need review" in order to finish with this issue and by the same time with "#3356400: Drupal 10 compatibility"
wich is almost duplicate now.
Comment #39
weseze commentedI can confirm that the patch from #37 applies to the latest v4.0.3 version of the module and everything is working as expected.
Setting to "Needs review" so the maintainers can have a look and provide feedback, if needed.
Comment #40
nigelcunningham commented@weseze, the status you actually want is RTBC since you've said you've confirmed it works. Updating to that.