You are here

function i18n_menu_node_block_info in Menu translation - Node 7

Implementation of hook_block_info().

Provide an i18n version of each menu block.

1 call to i18n_menu_node_block_info()
i18n_menu_node_block_view in ./i18n_menu_node.module
Implementation of hook_block_view().

File

./i18n_menu_node.module, line 55
Menu translation (Node).

Code

function i18n_menu_node_block_info() {
  $blocks = array();
  $schema = drupal_get_schema('block');
  $max_length = $schema['fields']['delta']['length'];
  $separator = I18N_MENU_NODE_BLOCK_SEPARATOR;

  // Retrieve blocks from all the modules defined in the block information.
  foreach (i18n_menu_node_block_module_info() as $module => $data) {
    $module_blocks = module_invoke($module, 'block_info');
    if (!empty($module_blocks)) {

      // If a delta set is specified filter out the undesired blocks.
      if (!empty($data['delta'])) {
        $module_blocks = array_intersect_key($module_blocks, array_flip($data['delta']));
      }

      // Create an [i18n] version for each block and store the parent module
      // as part of the delta.
      foreach ($module_blocks as $delta => $block) {

        // Truncate the [i18n] block delta to the maximum allowed length and
        // check that there is no block with such a delta already defined.
        $mtn_delta = substr($module . $separator . $delta, 0, $max_length);
        if (!isset($blocks[$mtn_delta])) {
          $blocks[$mtn_delta]['info'] = t('[i18n] !block', array(
            '!block' => $block['info'],
          ));

          // Inherit block settings except for the 'info' key.
          $blocks[$mtn_delta] += $block;
        }
        else {
          $limit = $max_length - strlen($module . $separator);
          $info = str_replace('[i18n] ', '', $blocks[$mtn_delta]['info']);
          drupal_set_message(t('The [i18n] version of <em>@current_block</em> cannot be provided: the block identifier is already assigned to <em>@block</em>. Try to change the original block identifier before character !limit.', array(
            '@current_block' => $block['info'],
            '@block' => $info,
            '!limit' => $limit,
          )), 'warning', FALSE);
        }
      }
    }
  }
  return $blocks;
}