You are here

service_container_block.module in Service Container 7.2

Main module file for the service_container_block module.

File

modules/utility/service_container_block/service_container_block.module
View source
<?php

/**
 * @file
 * Main module file for the service_container_block module.
 */

/**
 * Implements hook_block_info().
 */
function service_container_block_block_info() {
  $blocks = array();
  $plugin_manager = \Drupal::service('plugin.manager.block');
  foreach ($plugin_manager
    ->getDefinitions() as $definition) {
    if (strlen($definition['id']) <= 32) {
      $blocks[$definition['id']]['info'] = $definition['admin_label'];
    }
  }
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function service_container_block_block_view($delta = '') {
  $definition = \Drupal::service('plugin.manager.block')
    ->getDefinition($delta);
  if ($definition) {
    $block = \Drupal::service('plugin.manager.block')
      ->createInstance($delta);
    return array(
      'content' => $block
        ->build(),
    );
  }
}