5

page.tpl.php の $tabs を含むブロックを作成したい

/**
 * 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;
}



ブロックは正しく登録されており、レンダリングされたタブで正しく表示されています。ただし、Drupal は多くのエラーをスローします。

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).
4

2 に答える 2

0

問題はテーマ機能にあるようです。

私はこれを使ってみましたが、うまくいきます

$tabs =  menu_local_tasks(0);
$block['content'] =  $tabs['tabs']['output'];
于 2012-11-02T13:03:23.263 に答える
0

このタスクを完了するモジュールblockifyと、他の page.tpl.php 要素の作成があります。また、「ブロック」する要素の管理ページも提供します。

于 2015-04-16T17:18:47.273 に答える