function OliveroHooks::themeSuggestionsBlockAlter

Implements hook_theme_suggestions_HOOK_alter() for block().

Attributes

#[Hook('theme_suggestions_block_alter')]

File

core/themes/olivero/src/Hook/OliveroHooks.php, line 191

Class

OliveroHooks
Hook implementations for olivero.

Namespace

Drupal\olivero\Hook

Code

public function themeSuggestionsBlockAlter(&$suggestions, array $variables) : void {
  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.