Content create links in Drupal Navigation menu always go to top-level node/add

Created on 18 May 2024, 29 days ago
Updated 1 June 2024, 15 days ago

Problem/Motivation

When using the new experimental Drupal Navigation integration, the links for adding each content type do not go to /node/add/[content-type] but rather just /node/add, forcing you to select a content type again.

Steps to reproduce

  1. In the Gin theme settings, set the toolbar option to "New Drupal Navigation, Test integration" and save
  2. Click on any one of the content types under "Create" in the toolbar

Proposed resolution

In src/GinNavigation.php on line 94 it sets the $create_item_url variable to Url::fromRoute('node.add_page')->toString(); and then uses that for all the content types. Remove that and instead in the loop of the content types do this:

$create_item_url = Url::fromRoute('node.add', ['node_type' => $item->id()])->toString();

I've tested this locally and it works as expected.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada teknocat

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

Merge Requests

Comments & Activities

  • Issue created by @teknocat
  • πŸ‡¨πŸ‡¦Canada teknocat

    Actually the ->toString() isn't needed and it doesn't need to be set in a variable. It can just follow the same pattern as for media and blocks:

    foreach ($content_types as $item) {
      $content_type_items[] = [
        'title' => $item->label(),
        'class' => $item->id(),
        'url' => Url::fromRoute('node.add', ['node_type' => $item->id()]),
      ];
    }
    
  • Merge request !421Fix create node nav links β†’ (Merged) created by teknocat
  • Pipeline finished with Success
    29 days ago
    Total: 307s
    #175636
  • Pipeline finished with Success
    29 days ago
    Total: 187s
    #175639
  • Status changed to RTBC 29 days ago
  • πŸ‡¨πŸ‡­Switzerland saschaeggi Zurich

    @teknocat great discovery, let's merge this! πŸ‘

  • Status changed to Fixed 29 days ago
  • πŸ‡¨πŸ‡­Switzerland saschaeggi Zurich
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024