function claro_preprocess_node_add_list

Same name and namespace in other branches
  1. 10 core/themes/claro/claro.theme \claro_preprocess_node_add_list()
  2. 9 core/themes/claro/claro.theme \claro_preprocess_node_add_list()
  3. 8.9.x core/themes/claro/claro.theme \claro_preprocess_node_add_list()

Implements hook_preprocess_HOOK() for node_add_list.

Makes node_add_list variables compatible with entity_add_list.

File

core/themes/claro/claro.theme, line 140

Code

function claro_preprocess_node_add_list(&$variables) : void {
  if (!empty($variables['content'])) {
    /** @var \Drupal\node\NodeTypeInterface $type */
    foreach ($variables['content'] as $type) {
      $label = $type->label();
      $description = $type->getDescription();
      $type_id = $type->id();
      $add_url = Url::fromRoute('entity.node.add_form', [
        'node_type' => $type_id,
      ]);
      $variables['bundles'][$type_id] = [
        'label' => $label,
        'add_link' => Link::fromTextAndUrl($label, $add_url),
        'description' => [],
      ];
      if (!empty($description)) {
        $variables['bundles'][$type_id]['description'] = [
          '#markup' => $description,
        ];
      }
    }
    $variables['attributes']['class'][] = 'node-type-list';
  }
}

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