Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
HEAT-6742943: Fix "node_add_list" urls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jelle-S committed Aug 30, 2024
1 parent bd0828f commit ddce4e0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions og_sm_content/og_sm_content.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
}

/**
Expand Down

0 comments on commit ddce4e0

Please sign in to comment.