You are here

function sharerich_block_info in Sharerich 7.2

Same name and namespace in other branches
  1. 7.3 sharerich.module \sharerich_block_info()
  2. 7 sharerich.module \sharerich_block_info()

Implements hook_block_info().

File

./sharerich.module, line 144

Code

function sharerich_block_info() {
  $sharerich_sets = sharerich_sets_load_all();
  $blocks = array();
  $hashes = array();
  foreach ($sharerich_sets as $sharerich_set) {
    if (!$sharerich_set->block) {
      continue;
    }

    // Create a hash when the machine name is too big.
    //
    // This issue is fixed starting with drupal 7.33 release
    // https://www.drupal.org/node/466576
    // Keeping the workaround for older releases.
    if (drupal_strlen($sharerich_set->machinename) >= 32) {
      $delta = md5($sharerich_set->machinename);
      $hashes[$delta] = $sharerich_set->machinename;
    }
    else {
      $delta = $sharerich_set->machinename;
    }
    $blocks[$delta]['info'] = t('Sharerich set: @name', array(
      '@name' => $sharerich_set->machinename,
    ));
    $blocks[$delta]['cache'] = DRUPAL_CACHE_PER_PAGE;
  }

  // Only save hashes if they have changed.
  $old_hashes = variable_get('sharerich_block_hashes', array());
  if ($hashes != $old_hashes) {
    variable_set('sharerich_block_hashes', $hashes);
  }
  return $blocks;
}