From ddce4e09cd6906e6b0e352837cbea17a2f814943 Mon Sep 17 00:00:00 2001 From: Jelle Sebreghts Date: Fri, 30 Aug 2024 12:27:58 +0200 Subject: [PATCH] HEAT-6742943: Fix "node_add_list" urls This module alters the URLs for the "node_add_list" page. The problem is these URLs are present in different variables for the twig files. Depending on the theme the "bundles" variable or the "types" variable is used. This fix makes sure both variables contain the same URLs. --- og_sm_content/og_sm_content.module | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/og_sm_content/og_sm_content.module b/og_sm_content/og_sm_content.module index 4c3b4a4..9d2bb22 100644 --- a/og_sm_content/og_sm_content.module +++ b/og_sm_content/og_sm_content.module @@ -8,6 +8,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Link; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\og_sm\OgSm; @@ -126,19 +127,19 @@ function og_sm_content_preprocess_node_add_list(&$variables) { return; } - /** @var \Drupal\Core\Utility\LinkGeneratorInterface $link_generator */ - $link_generator = \Drupal::service('link_generator'); foreach ($variables['content'] as $type) { /** @var \Drupal\node\NodeTypeInterface $type */ $url = new Url('og_sm.site_content.add', [ 'node' => $site->id(), 'node_type' => $type->id(), ]); - $variables['types'][$type->id()]['add_link'] = $link_generator->generate($type->label(), $url); + $variables['types'][$type->id()]['add_link'] = Link::fromTextAndUrl($type->label(), $url); // Also set the url key since themes like seven have a custom template for // node_add_list. $variables['types'][$type->id()]['url'] = $url; } + // Claro/Gin use the bundle variable in their templates (cfr entity_add_list) + $variables['bundles'] = $variables['types']; } /**