function PreprocessHooks::blockContentAddList
Same name and namespace in other branches
- main core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::blockContentAddList()
Implements hook_preprocess_HOOK() for block_content_add_list.
Makes block_content_add_list variables compatible with entity_add_list.
Attributes
#[Hook('preprocess_block_content_add_list')]
File
-
core/
themes/ admin/ src/ Hook/ PreprocessHooks.php, line 136
Class
- PreprocessHooks
- Provides preprocess implementations.
Namespace
Drupal\admin\HookCode
public function blockContentAddList(array &$variables) : void {
if (!empty($variables['content'])) {
$query = $this->requestStack
->getCurrentRequest()->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,
];
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.