function claro_preprocess_block_content_add_list in Drupal 9
Same name and namespace in other branches
- 8 core/themes/claro/claro.theme \claro_preprocess_block_content_add_list()
Implements template_preprocess_HOOK() for block_content_add_list.
Makes block_content_add_list variables compatible with entity_add_list.
File
- core/
themes/ claro/ claro.theme, line 138 - Functions to support theming in the Claro theme.
Code
function claro_preprocess_block_content_add_list(&$variables) {
if (!empty($variables['content'])) {
$query = \Drupal::request()->query
->all();
/** @var \Drupal\block_content\BlockContentTypeInterface $type */
foreach ($variables['content'] as $type) {
$label = $type
->label();
$description = $type
->getDescription();
$type_id = $type
->id();
$add_url = Url::fromRoute('block_content.add_form', [
'block_content_type' => $type_id,
], [
'query' => $query,
]);
$variables['bundles'][$type_id] = [
'label' => $label,
'add_link' => Link::fromTextAndUrl($label, $add_url),
'description' => [],
];
if (!empty($description)) {
$variables['bundles'][$type_id]['description'] = [
'#markup' => $description,
];
}
}
}
}