function olivero_theme_suggestions_block_alter

Same name and namespace in other branches
  1. 9 core/themes/olivero/olivero.theme \olivero_theme_suggestions_block_alter()
  2. 10 core/themes/olivero/olivero.theme \olivero_theme_suggestions_block_alter()

Implements hook_theme_suggestions_HOOK_alter() for block().

File

core/themes/olivero/olivero.theme, line 220

Code

function olivero_theme_suggestions_block_alter(&$suggestions, array $variables) {
    if (!empty($variables['elements']['#id'])) {
        
        /** @var \Drupal\block\BlockInterface $block */
        $block = \Drupal::entityTypeManager()->getStorage('block')
            ->load($variables['elements']['#id']);
        if ($block) {
            // Add region-specific block theme suggestions.
            $region = $block->getRegion();
            $suggestions[] = 'block__' . $region;
            $suggestions[] = 'block__' . $region . '__' . 'plugin_id' . '__' . $variables['elements']['#plugin_id'];
            $suggestions[] = 'block__' . $region . '__' . 'id' . '__' . $variables['elements']['#id'];
        }
    }
}

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