Explore block module in Drupal
来源:互联网 发布:linux 总线驱动 编辑:程序博客网 时间:2024/05/16 12:38
block.info is the block module description file and the "package" property tells us that block is Drupal core module and it can be configured by menu "admin/structure/block".
block.install is executed when block is installed. The purpose of this file is to create the necessary tables: block, block_custom, block_role
- Table block is used to store the block information declared by code statements;
- Table block_custom is used to store the block information created by administration interface;
- Table block_role is used to control the visibility of blocks.
The main logic are defined in the block.module file. Let us go around this file.There are lots of functions in block.module,but they can be categorized into two types: hook function and block module internal-used function.hook function includes block_menu, block_theme, block_theme_initialize, block_themes_enable.
- Function block_menu:block configuration, block management, block list by theme
function block_menu() { $default_theme = variable_get('theme_default', 'bartik'); $items['admin/structure/block'] = array( 'title' => 'Blocks', 'description' => 'Configure what block content appears in your site\'s sidebars and other regions.', 'page callback' => 'block_admin_display', 'page arguments' => array($default_theme), 'access arguments' => array('administer blocks'), 'file' => 'block.admin.inc', ); $items['admin/structure/block/manage/%/%'] = array( 'title' => 'Configure block', 'page callback' => 'drupal_get_form', 'page arguments' => array('block_admin_configure', 4, 5), 'access arguments' => array('administer blocks'), 'file' => 'block.admin.inc', ); $items['admin/structure/block/manage/%/%/configure'] = array( 'title' => 'Configure block', 'type' => MENU_DEFAULT_LOCAL_TASK, 'context' => MENU_CONTEXT_INLINE, ); $items['admin/structure/block/manage/%/%/delete'] = array( 'title' => 'Delete block', 'page callback' => 'drupal_get_form', 'page arguments' => array('block_custom_block_delete', 4, 5), 'access arguments' => array('administer blocks'), 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_NONE, 'file' => 'block.admin.inc', ); $items['admin/structure/block/add'] = array( 'title' => 'Add block', 'page callback' => 'drupal_get_form', 'page arguments' => array('block_add_block_form'), 'access arguments' => array('administer blocks'), 'type' => MENU_LOCAL_ACTION, 'file' => 'block.admin.inc', ); foreach (list_themes() as $key => $theme) { $items['admin/structure/block/list/' . $key] = array( 'title' => check_plain($theme->info['name']), 'page arguments' => array($key), 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, 'weight' => $key == $default_theme ? -10 : 0, 'access callback' => '_block_themes_access', 'access arguments' => array($theme), 'file' => 'block.admin.inc', ); if ($key != $default_theme) { $items['admin/structure/block/list/' . $key . '/add'] = array( 'title' => 'Add block', 'page callback' => 'drupal_get_form', 'page arguments' => array('block_add_block_form'), 'access arguments' => array('administer blocks'), 'type' => MENU_LOCAL_ACTION, 'file' => 'block.admin.inc', ); } $items['admin/structure/block/demo/' . $key] = array( 'title' => check_plain($theme->info['name']), 'page callback' => 'block_admin_demo', 'page arguments' => array($key), 'type' => MENU_CALLBACK, 'access callback' => '_block_themes_access', 'access arguments' => array($theme), 'theme callback' => '_block_custom_theme', 'theme arguments' => array($key), 'file' => 'block.admin.inc', ); } return $items;}
- Function block_theme: offers two theme options: block is for front-end and block_admin_display_form is for administration interface
function block_theme() { return array( 'block' => array( 'render element' => 'elements', 'template' => 'block', ), 'block_admin_display_form' => array( 'template' => 'block-admin-display-form', 'file' => 'block.admin.inc', 'render element' => 'form', ), );}
- Function block_theme_initialize: assign the blocks to theme's regions
function block_theme_initialize($theme) { // Initialize theme's blocks if none already registered. $has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField(); if (!$has_blocks) { $default_theme = variable_get('theme_default', 'bartik'); // Apply only to new theme's visible regions. $regions = system_region_list($theme, REGIONS_VISIBLE); $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC)); foreach ($result as $block) { // If the region isn't supported by the theme, assign the block to the theme's default region. if ($block['status'] && !isset($regions[$block['region']])) { $block['region'] = system_default_region($theme); } $block['theme'] = $theme; unset($block['bid']); drupal_write_record('block', $block); } }}
- Function block_themes_enable: iterate the theme list and assign block list to its regions.
function block_themes_enabled($theme_list) { foreach ($theme_list as $theme) { block_theme_initialize($theme); }}
- Explore block module in Drupal
- Drupal——module开发实现简单block
- Drupal Module - Gmap
- Drupal Module - Location
- Drupal Module - Rules
- Drupal Module - imagefield
- Drupal Module - Taxonomy redirect
- drupal一些module
- Drupal search module
- drupal useful addition module
- drupal install module
- drupal 自定义block
- Learning Drupal 6 Module Development
- Drupal Module - SMTP Authentication Support
- Drupal Module – PNG Fix
- Drupal – Cumulus Cloud Module
- Drupal Module – Location bug
- Drupal Module - Taxonomy Access Control
- 16周:带姓名的成绩单(字符数组版)
- mfc 利用HBITMAP 和CBITMAP 显示位图文件
- 带姓名的成绩单(字符数组版)
- 嵌入式系统是发展先进制造业的关键
- wampserver 网站访问非常缓慢的问题.
- Explore block module in Drupal
- TestPrepStmt(24)
- C++ Debug指针错误的说明
- TimePicker在ScrollView中滑动冲突的解决方法(更新适用于全控件的方法)
- 传工信部酝酿APP备案制 开发者称操作性不强
- [Leetcode] Permutations II
- Windows 7如何还原字体的默认设置
- 优秀程序员不得不知道的20个位运算技巧
- Asp.Net中List泛型数组的参数传递和遍历(示例源码)