Explore block module in Drupal

Source: Internet
Author: User
Tags drupal

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; Tabl E 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 between des bloc K_menu, block_theme, block_theme_initialize, block_menu: block configuration, block management, block list by theme [html] $ default_theme = variable_get ('Theme _ default', 'bartik '); $ items ['admin/structure/Block'] = array ('title' => 'buckets ', 'description' => 'configure what block content appears in your site \'s sidebars and other regions. ', 'page callback' =>' block _ adm In_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 ',); $ I Tems ['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 blocs'),'t Ype '=> 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 ['n' Ame']), '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_admi N_display_form is for administration interface [html] 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 [php] function bloc K_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 B Lock 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. [html] function block_themes_enabled ($ theme_list) {foreach ($ theme_list as $ theme) {block_theme_initialize ($ theme );}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.