1

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;
  }
}
apaderno
  • 28,547
  • 16
  • 75
  • 90
user001
  • 441
  • 3
  • 8
  • 24
  • please mark good answers as "accepted" so the question can be closed. It's the green check mark. – Dawson Mar 13 '11 at 16:48

2 Answers2

1

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;
      }
   }
}
Artusamak
  • 2,470
  • 19
  • 19
  • Almost good solution, i'm looking for 1 block with more then 1 menu items in it. – user001 Mar 11 '11 at 08:12
  • 1
    Well it means that they are not in the title so, right? If you want to list items use the theme_item_list() function. I added an example. – Artusamak Mar 11 '11 at 09:25
1

You can either create multiple blocks as shown in Artusamak's answer, or you can simply add more content to $blocks['content'] if you want it in a single block.

$blocks['content'] = l('admin/settings/1', 'test 1') . ' ' . l('admin/settings/2', 'test 2');

Note, if you just want a list of fixed links, you can do that by creating a menu and adding links to it. Every menu is automatically exposed as a block. No custom code required.

Berdir
  • 6,881
  • 2
  • 26
  • 38