Same name and namespace in other branches
  1. 8.9.x core/modules/node/node.module \template_preprocess_node_add_list()
  2. 9 core/modules/node/node.module \template_preprocess_node_add_list()

Prepares variables for list of available node type templates.

Default template: node-add-list.html.twig.

Parameters

array $variables: An associative array containing:

  • content: An array of content types.

See also

\Drupal\node\Controller\NodeController::addPage()

File

core/modules/node/node.module, line 424
The core module that allows content to be submitted to the site.

Code

function template_preprocess_node_add_list(&$variables) {
  $variables['types'] = [];
  if (!empty($variables['content'])) {
    foreach ($variables['content'] as $type) {
      $variables['types'][$type
        ->id()] = [
        'type' => $type
          ->id(),
        'add_link' => Link::fromTextAndUrl($type
          ->label(), Url::fromRoute('node.add', [
          'node_type' => $type
            ->id(),
        ]))
          ->toString(),
        'description' => [
          '#markup' => $type
            ->getDescription(),
        ],
      ];
    }
  }
}