You are here

function mmenu_get_blocks in Mobile sliding menu 8

Same name and namespace in other branches
  1. 7.3 mmenu.module \mmenu_get_blocks()
  2. 7 mmenu.module \mmenu_get_blocks()
  3. 7.2 mmenu.module \mmenu_get_blocks()

Gets all Drupal blocks for assigning to a mmenu.

Return value

array An associative array contains all Drupal blocks.

1 call to mmenu_get_blocks()
MmenuSettingsForm::buildForm in src/Form/MmenuSettingsForm.php
Form constructor.

File

./mmenu.module, line 891
Primarily Drupal hooks and global API functions to manipulate mmenus.

Code

function mmenu_get_blocks() {
  $blockManager = \Drupal::service('plugin.manager.block');
  $contextRepository = \Drupal::service('context.repository');
  $available_plugins = $blockManager
    ->getDefinitionsForContexts($contextRepository
    ->getAvailableContexts());
  $available_plugins = $blockManager
    ->getSortedDefinitions($available_plugins);
  $options = [];
  foreach ($available_plugins as $key => $definition) {
    if ($definition['category'] instanceof TranslatableMarkup) {
      $category = $definition['category']
        ->render();
    }
    else {
      $category = $definition['category'];
    }
    $admin_label = $definition['admin_label'];
    $options[$category][$key] = $category . ' - ' . $admin_label;
  }

  //  dpm($options);
  return $options;

  //  $block_ids = \Drupal::entityQuery('block')
  //    ->execute();
  //
  //  $drupal_blocks = array();
  //  foreach ($block_ids as $block_id) {
  //    $block = Block::load($block_id);
  //    $dependencies = $block->getDependencies();
  //    if (!empty($dependencies['module']) && $module = current($dependencies['module'])) {
  //      if (empty($drupal_blocks[$module])) {
  //        $drupal_blocks[$module] = array();
  //      }
  //      $drupal_blocks[$module][$block_id] = $block;
  //    }
  //  }
  //  return $drupal_blocks;
}