W3cubDocs

/Drupal 8

function template_preprocess_node_add_list

template_preprocess_node_add_list(&$variables)

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

node_add_page()

File

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

Code

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!node!node.module/function/template_preprocess_node_add_list/8.1.x