You are here

function block_skinr_ui_element_options in Skinr 8.2

Same name and namespace in other branches
  1. 7.2 modules/block.skinr.inc \block_skinr_ui_element_options()

Implements hook_skinr_ui_element_options().

File

modules/block.skinr.inc, line 21
Implements Skinr hooks for block.module.

Code

function block_skinr_ui_element_options($theme_name = NULL) {
  $options = array(
    'block' => array(),
  );
  $theme_handler = \Drupal::service('theme_handler');

  /** @var Extension[]|\stdClass[] $themes */
  $themes = $theme_handler
    ->listInfo();
  $used_themes = array();
  if ($theme_name) {

    // Only process the given theme.
    $used_themes[] = $theme_name;
  }
  else {

    // Process all enabled themes.
    foreach ($themes as $theme) {
      if (!$theme->status) {
        continue;
      }
      $used_themes[] = $theme
        ->getName();
    }
  }

  // Load all enabled blocks.
  foreach ($used_themes as $theme) {
    $blocks = _block_skinr_load_blocks($theme);
    $theme_title = isset($themes[$theme]->info['name']) ? $themes[$theme]->info['name'] : $theme;
    foreach ($blocks as $block_id => $block) {
      $options['block'][$theme_title][$block_id] = $block
        ->label();
    }
  }
  return $options;
}