You are here

16.2 页面数组的合成

admin 的头像
Submitted by admin on 星期四, 2015-07-30 09:27

作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

这是我们这里实际执行的语句。用来合成页面的是drupal_render_page函数。这个时候,传递过来的$page_callback_result,只是一个包含节点对象的呈现数组,节点外面的区域、区块是怎么加进来的呢?这是很多初学者的疑问。让我们来看这个函数的定义:

/**

 * Renders the page, including all theming.

 *

 * @param $page

 *   A string or array representing the content of a page. The array consists of

 *   the following keys:

 *   - #type: Value is always 'page'. This pushes the theming through

 *     page.tpl.php (required).

 *   - #show_messages: Suppress drupal_get_message() items. Used by Batch

 *     API (optional).

 *

 * @see hook_page_alter()

 * @see element_info()

 */

function drupal_render_page($page) {

  $main_content_display = &drupal_static('system_main_content_added', FALSE);

 

  // Allow menu callbacks to return strings or arbitrary arrays to render.

  // If the array returned is not of #type page directly, we need to fill

  // in the page with defaults.

  if (is_string($page) || (is_array($page) && (!isset($page['#type']) || ($page['#type'] != 'page')))) {

    drupal_set_page_content($page);

    $page = element_info('page');

  }

 

  // Modules can add elements to $page as needed in hook_page_build().

  foreach (module_implements('page_build') as $module) {

    $function = $module . '_page_build';

    $function($page);

  }

  // Modules alter the $page as needed. Blocks are populated into regions like

  // 'sidebar_first', 'footer', etc.

  drupal_alter('page', $page);

 

  // If no module has taken care of the main content, add it to the page now.

  // This allows the site to still be usable even if no modules that

  // control page regions (for example, the Block module) are enabled.

  if (!$main_content_display) {

    $page['content']['system_main'] = drupal_set_page_content();

  }

 

  return drupal_render($page);

}

这个时候会组装$page这个数组,开始的时候,只包含节点部分,注意往下执行的时候,粗体部分的代码,定义了hook_page_build钩子函数,允许其它模块向$page数组追加内容。难道block模块实现了这个钩子函数?


Drupal版本: