function PreprocessHooks::nodeAddList
Same name and namespace in other branches
- main core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::nodeAddList()
Implements hook_preprocess_HOOK() for node_add_list.
Makes node_add_list variables compatible with entity_add_list.
Attributes
#[Hook('preprocess_node_add_list')]
File
-
core/
themes/ admin/ src/ Hook/ PreprocessHooks.php, line 991
Class
- PreprocessHooks
- Provides preprocess implementations.
Namespace
Drupal\admin\HookCode
public function nodeAddList(array &$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('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.