Explore block module in drupal_php tutorial

Source: Internet
Author: User
Tags drupal
Block.info is the Block module description file and the ' package ' property tells us, block is Drupal core module and It can be configured by menu "Admin/structure/block". Block.install is executed when the block is installed. The purpose of this file are to create the necessary Tables:block, Block_custom, block_role Table block are used to store t He 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 is defined in the Block.module file. Let us go around the this file. There is lots of functions in block.module,but they can is categorized into the Types:hook function and block module int ernal-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[html] $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, ' fi Le ' = ' block.admin.inc ',); $items [' admin/structure/block/add '] = Array (' title ' = = ' Add block ', ' page callback ' = ' drupal_get_form ', ' page arg ' Uments ' = = 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_p Lain ($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 ' =&gt ; 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 ' =&gt ; ' _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 Theme Options:block is for front-end and block_admin_display_form are for Administratio N interface[html] Function block_theme () {return Array (' block ' = = Array (' render element ' = ' elements ', ' template ' = ' and ' 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 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 is ' t supported by the theme, assign the block to the theme ' s default Regio N. 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);}}

http://www.bkjia.com/PHPjc/477871.html www.bkjia.com true http://www.bkjia.com/PHPjc/477871.html techarticle Block.info is the Block module description file and the Package property tells us, block is Drupal core module and It can be configured by menu Admin/structure/block. Block.inst ...

  • 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.