How to use modules in Drupal
来源:互联网 发布:为知笔记 密码 编辑:程序博客网 时间:2024/05/20 06:54
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;
- How to use modules in Drupal
- How to use tinyfck in drupal
- How To Enable Apache Modules in Ubuntu
- How to store node content in Drupal
- How to use Serial Port in Windows
- How To Use Macro In Program.
- How to use virt-install in OpenSolaris
- How to use Regular Expression in LotusScript
- How to Use PeekMessage() Correctly in Windows
- How to use IMGDECMP.DLL in WindowsCE
- how to use deb files in ubuntu
- How to use Common Navigator in RCP
- How to use SCAT in ECC6
- HOW TO : use DDMS in Ubuntu
- How to use getBodyClass() in magento?
- How to use forms in Tapestry 5.
- How to use svn in Linux
- How to use git in Linux
- WinCE开机默认语言设置 .
- 什么是WCF
- Oracle常用语法,练习中发现的薄弱语法。
- latex在ubuntu/debain下的中文配置
- hdu 2544 最短路
- How to use modules in Drupal
- java中执行sql脚本
- linux重定向
- OpenWrt使用笔记之Dropbear
- NSCondition的用法
- OpenGL常见问题以及解决办法
- Web services与SOA
- 用闪烁的“方框”去定位待编辑的Edit
- exe文件转化为系统服务