function template_preprocess_node_add_list

Same name and namespace in other branches
  1. 9 core/modules/node/node.module \template_preprocess_node_add_list()
  2. 8.9.x core/modules/node/node.module \template_preprocess_node_add_list()
  3. 10 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 368

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(),
                ],
            ];
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.