Search code examples
phpdrupaldrupal-blocks

content block with more than 1 content items


The following code is a Drupal block made in php.
1) How can I implement more then one item? now i have test1 but i want test1, test2, test3 and test5.
2) how can i link a title for example test1 to my admin/settings/ menu? I want to link an item to node_import in Drupal.

function planning_block($op='list', $delta=0, $edit=array()) {
  switch ($op) {
    case 'list':
        $blocks[0]['info'] = t('Stage administration block');
        return $blocks;
    case 'view':
        $blocks['subject'] = t('Stage administratie');
        $blocks['content'] = 'test';
        return $blocks;
  }
}

Solution

  • If you refer to the documentation of hook_block, you can declare several block inside one hook.

    The $delta argument is here to help you differenciate which block your are rendering.

    About your links in the title, just use the l() function when you are setting the $block['subject'] value.

    Example:

    function planning_block($op='list', $delta=0, $edit=array()) {
      switch ($op) {
        case 'list':
          $blocks[0]['info'] = t('Stage administration block 1');
          $blocks[1]['info'] = t('Stage administration block 2');
          return $blocks;
        case 'view':
          switch ($delta) {
            case 0:
              $blocks['subject'] = t('Stage administratie');
              $items = array(
                l('Item 1', 'admin/settings/1'),
                l('Item 2', 'admin/settings/2'),
              );
              $blocks['content'] = theme_item_list($items);
              return $blocks;
            case 1:
              $blocks['subject'] = l('admin/settings/2', t('Stage administratie 2'));
              $blocks['content'] = 'test 2';
              return $blocks;
          }
       }
    }