1 block.module block_block_info()

Implements hook_block_info().

File

core/modules/block/block.module, line 100
Provides the ability to create reusable custom blocks.

Code

function block_block_info() {
  global $language;
  $langcode = $language->langcode;

  // Statically cache to prevent multiple database lookups.
  $blocks = &backdrop_static(__FUNCTION__);
  if (isset($blocks)) {
    return $blocks;
  }

  $blocks = array();
  $config_names = config_get_names_with_prefix('block.custom.');
  foreach ($config_names as $config_name) {
    $block = config_get($config_name);
    $block_info = array();
    $block_info['info'] = $block['info'];
    $block_info['description'] = !empty($block['description']) ? $block['description'] : NULL;

    // If this block has been translated, return the translated information.
    if (isset($block['translations'][$langcode])) {
      $block_info['info'] = $block['translations'][$langcode]['info'];
      $block_info['description'] = $block['translations'][$langcode]['description'];
    }
    // If no description was entered, use a generic one.
    if (empty($block_info['description'])) {
      $block_info['description'] = t('A reusable custom block.');
    }
    $blocks[$block['delta']] = $block_info;
  }

  return $blocks;
}