function claro_preprocess_block_content_add_list

Same name and namespace in other branches
  1. 9 core/themes/claro/claro.theme \claro_preprocess_block_content_add_list()
  2. 8.9.x core/themes/claro/claro.theme \claro_preprocess_block_content_add_list()
  3. 10 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 159

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,
                ];
            }
        }
    }
}

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