function claro_preprocess_node_add_list

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

Implements template_preprocess_HOOK() for node_add_list.

Makes node_add_list variables compatible with entity_add_list.

File

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

Code

function claro_preprocess_node_add_list(&$variables) {
    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('node.add', [
                '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.