5

I want to create a block which contains the $tabs from page.tpl.php

/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {

  $blocks['tabs'] = array(
    'info' => t('Tabs in block'),
    'description' => t('blah blah blah'),
  );
  return $blocks;
}


/**
 * Implements hook_block_view().
 */
function mymodule_block_view($delta = '') {

  $block = array();

  switch ($delta) {

    case 'tabs':
      $block['subject'] = t("THIS IS ZHE TABS!");
      $block['content'] = array(
        '#theme' => 'menu_local_tasks',
        '#primary' => menu_local_tasks(0),
        '#secondary' => menu_local_tasks(1),
      );
    break;
  }
  return $block;
}



The block is being registered correctly and is showing up correctly with the tabs rendered. However, Drupal throws a lot of errors!

Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5777 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5815 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5777 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5815 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
apaderno
  • 28,547
  • 16
  • 75
  • 90
tolborg
  • 612
  • 4
  • 21

2 Answers2

0

It seems the problem is in the theme function, maybe.

I tried using this and it works

$tabs =  menu_local_tasks(0);
$block['content'] =  $tabs['tabs']['output'];
rafinskipg
  • 509
  • 5
  • 10
0

There is the module blockify that completes this task and the creation of other page.tpl.php elements for you. It also gives the admin page for which elements to "blockify"

timodwhit
  • 111
  • 3