Context exception when trying to create url (Drupal 10 is broken!)

Created on 29 July 2022, over 2 years ago
Updated 4 September 2024, 4 months ago

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.

πŸ› Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States loopy1492

    Just adding a static patch after @daveiano's work above...

  • πŸ‡ΊπŸ‡ΈUnited States loopy1492

    For some reason I keep uploading patches that start with a space in the file name.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΈπŸ‡°Slovakia coaston

    #18 resolved issues in D10.

    Thank you. You have saved my day!

  • Status changed to RTBC over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Any maintainer here to merge this and tag a new 4.x release, as 4.x isn't really D10 compatible currently.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡ΊπŸ‡ΈUnited States andysipple

    Getting the following error when trying to config import into a D10 site. Patch #18 is not working for me.

    +------------+------------------------------+-----------+
    | Collection | Config                       | Operation |
    +------------+------------------------------+-----------+
    |            | view_mode_page.pattern.print | Create    |
    +------------+------------------------------+-----------+
    
     Import the listed configuration changes? (yes/no) [yes]:
     > yes
    
     [notice] Synchronized configuration: create view_mode_page.pattern.print.
     [notice] Finalizing configuration synchronization.
    
    In ConfigImportCommands.php line 324:
                                                                                                                                                                 
      The import failed due to the following reasons:                                                                                                            
      Unexpected error during import with operation create for view_mode_page.pattern.print: The "node_type" plugin does not exist. Valid plugin IDs   
      for Drupal\Core\Condition\ConditionManager are: config_pages_values_access, gtag_domain, gtag_language, language, current_theme, request_path, user_role,  
       webform, entity_bundle:block_content, entity_bundle:config_pages, entity_bundle:crop, entity_bundle:entity_subqueue, entity_bundle:feeds_feed, entity_bu  
      ndle:media, entity_bundle:menu_link_content, entity_bundle:node, entity_bundle:redirect, entity_bundle:taxonomy_term, entity_bundle:webform_submission, e  
      ntity_bundle:paragraph 
  • πŸ‡ΊπŸ‡ΈUnited States nkraft

    The patch in #18 PLUS the config update in #23 from AndySimple worked for me!

    I applied patch #18.
    Then went into my config sync folder, searched for: node_type
    And then changes all instances related to view_mode_page from:
    node_type to entity_bundle:node

    then ran: drush cim
    top import the modified config files
    then
    drush cr

    And voila! My view mode pages are back and working correctly! Thanks alll, you saved my day, getting ready to take D10 live hopefully tomorrow. Cheers to you all.

  • πŸ‡§πŸ‡ͺBelgium stijnd Belgium

    The combination of #18 and #23 also worked for me. Perfectly explained by @nkraft!

  • Status changed to Needs work 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States pianomansam

    Changing 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.

  • With 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... πŸ› add pattern HTTP AJAX error 500 Active

  • πŸ‡ͺπŸ‡ΈSpain rcodina Barcelona

    The patch #18 works like a charm. But the MR patch doesn't apply.

Production build 0.71.5 2024