You are here

function media_gallery_block_info in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.module \media_gallery_block_info()

Implements hook_block_info().

File

./media_gallery.module, line 576

Code

function media_gallery_block_info() {
  $blocks = array();

  // Define a block for each media gallery node that is configured to expose
  // one.
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'node');
  $query
    ->entityCondition('bundle', 'media_gallery');
  $query
    ->fieldCondition('media_gallery_expose_block', 'value', 1);
  $result = $query
    ->execute();
  if (!empty($result['node'])) {

    // There is no reason to waste going through a full node_load_multiple()
    // when we only need the titles.
    $nids = array_keys($result['node']);
    $node_titles = db_query("SELECT nid, title FROM {node} WHERE nid IN (:nids)", array(
      ':nids' => $nids,
    ))
      ->fetchAllKeyed();
    foreach ($node_titles as $nid => $title) {

      // The 'info' element is escaped on display, so we pass it through
      // unfiltered here.
      $blocks[$nid]['info'] = t('Recent gallery items: !title', array(
        '!title' => $title,
      ));
      $blocks[$nid]['visibility'] = 0;
      $blocks[$nid]['pages'] = 'node/' . $nid . "\ngalleries";
    }
  }
  return $blocks;
}