The gutenberg_node_type_route hook is not working

Created on 14 November 2023, about 1 year ago
Updated 12 June 2024, 6 months ago

Steps to reproduce:
- Create content type "e.g. page" and enable gutenberg for it.
- Create group type using Group module
- Enable the "Page" content type in the group type.
- Create new group entity.
- Based on this, use the hook to fetch node type from the route as below.
- Try to create new page in the group, you won't see the gutenberg editor.

This is because this function will always return NULL after invoking the hooks...

function HOOK_gutenberg_node_type_route(RouteMatchInterface $route_match) {
  $route_name = $route_match->getRouteName();

  if ($route_name === 'entity.group_relationship.create_form') {
    $parameter = $route_match->getParameter('plugin_id');
    return explode(':', $parameter)[1];
  }

  return NULL;
}
🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇧🇪Belgium msnassar

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

Comments & Activities

  • Issue created by @msnassar
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    2 pass
  • Status changed to Needs work 8 months ago
  • 🇩🇪Germany szeidler Berlin

    The problem indeed exist. Without a return nothing will happen. But why do you have the assumption in your patch that hook_gutenberg_node_type_route() returns an array? Shouldn't that return simply the content type as a string?

  • Status changed to RTBC 8 months ago
  • 🇩🇪Germany szeidler Berlin

    No, you're right. Since it's not an alter, but invokeAll. The the approach is actually absolutely alright.

  • Status changed to Needs work 8 months ago
  • 🇩🇪Germany szeidler Berlin

    I still have problems to see how this can work. getGutenbergNodeTypeFromRoute

    if ($node_type) {
          // Then just return it.
          return $node_type->get('type');
        }
    

    $node_type is group:request for me and since the condition does not check if it's an NodeType object and fails with

    Error: Call to a member function get() on string in Drupal\gutenberg\GutenbergContentTypeManager->getGutenbergNodeTypeFromRoute() (line 120 of modules/contrib/gutenberg/src/GutenbergContentTypeManager.php).
    
  • 🇨🇭Switzerland colorfield Lausanne
  • 🇨🇭Switzerland colorfield Lausanne

    #2 works for me, we might just make it clearer in the example hook, to use entity.group_relationship.create_form instead of entity.group_content.create_form and ensure that the plugin is from group_node. Updated the patch with this.

    Also, not sure if we should account the weight of the hooks here, but taking the first available hook that implements it for a Gutenberg enabled node type looks good.

    For #7, it might indeed be that the route received a scalar parameter instead of the object because the route probably does not implement options parameters. So we could just check for NodeTypeInterface and NodeInterface here.

  • Status changed to Needs review 6 months ago
  • 🇨🇭Switzerland colorfield Lausanne
Production build 0.71.5 2024