When you finish a series of module actions: download, install and enable; you would wonder how front-end UI accesses or uses your installed modules. From Drupal's codes, i know that there are two ways: one is through menu, the other is by block.
1. Menu Way
function blog_menu() {
$items['blog'] = array(
'title' => 'Blogs',
'page callback' => 'blog_page_last',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
'file' => 'blog.pages.inc',
);
}You can make a menu in the front page and call blog_page_last when you access it. Referring to following code, blog_page_last returns array-type data.
function blog_page_last() {
global $user;
$build = array();
$query = db_select('node', 'n')->extend('PagerDefault');
$nids = $query
->fields('n', array('nid', 'sticky', 'created'))
->condition('type', 'blog')
->condition('status', 1)
->orderBy('sticky', 'DESC')
->orderBy('created', 'DESC')
->limit(variable_get('default_nodes_main', 10))
->addTag('node_access')
->execute()
->fetchCol();
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
$build += node_view_multiple($nodes);
$build['pager'] = array(
'#theme' => 'pager',
'#weight' => 5,
);
}
else {
drupal_set_message(t('No blog entries have been created.'));
}
drupal_add_feed('blog/feed', t('RSS - blogs'));
return $build;
}If callback function returns html markup data, it will show directly. If the page callback result is array-type data, it will use drupal_delivery_page method to render the content.
$page_callback_result = call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);drupal_deliver_page($page_callback_result, $default_delivery_callback);Let us examine drupal_deliver_page method's codes
function drupal_deliver_page($page_callback_result, $default_delivery_callback = NULL) {
if (!isset($default_delivery_callback) && ($router_item = menu_get_item())) {
$default_delivery_callback = $router_item['delivery_callback'];
}
$delivery_callback = !empty($default_delivery_callback) ? $default_delivery_callback : 'drupal_deliver_html_page';
// Give modules a chance to alter the delivery callback used, based on
// request-time context (e.g., HTTP request headers).
drupal_alter('page_delivery_callback', $delivery_callback);
if (function_exists($delivery_callback)) {
$delivery_callback($page_callback_result);
}
else {
// If a delivery callback is specified, but doesn't exist as a function,
// something is wrong, but don't print anything, since it's not known
// what format the response needs to be in.
watchdog('delivery callback not found', 'callback %callback not found: %q.', array('%callback' => $delivery_callback, '%q' => $_GET['q']), WATCHDOG_ERROR);
}
}The default callback is drupal_deliver_html_page, but there provides two options: delivery_callback and page_delivery_callback. delivery_callback is used in the menu definition and page_delivery_callback is for alter hook.
2 Block way
You can assign the block to one region and the block content will show in the region correspondingly.
function blog_block_view($delta = '') {
global $user;
if (user_access('access content')) {
$result = db_select('node', 'n')
->fields('n', array('nid', 'title', 'created'))
->condition('type', 'blog')
->condition('status', 1)
->orderBy('created', 'DESC')
->range(0, variable_get('blog_block_count', 10))
->addTag('node_access')
->execute();
if ($node_title_list = node_title_list($result)) {
$block['subject'] = t('Recent blog posts');
$block['content']['blog_list'] = $node_title_list;
$block['content']['blog_more'] = array(
'#theme' => 'more_link',
'#url' => 'blog',
'#title' => t('Read the latest blog entries.'),
);
return $block;
}
}
}
The regions are defined in the theme info files and can be managed by admin in the structure block area. the content is rendered by theme function hook_more_link.
if (isset($elements['#theme'])) {
$elements['#children'] = theme($elements['#theme'], $elements);
} $output = $prefix . $elements['#children'] . $suffix;
863

被折叠的 条评论
为什么被折叠?



