Home Backend Development PHP Tutorial Explore block module in Drupal_PHP tutorial

Explore block module in Drupal_PHP tutorial

Jul 14, 2016 am 10:07 AM
Block drupal explore module the

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
[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,  
    '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
[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 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. 
[html]  
function block_themes_enabled($theme_list) {  
  foreach ($theme_list as $theme) {  
    block_theme_initialize($theme);  
  }  
}  
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477871.htmlTechArticleblock.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.inst...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Moondrop releases Block true wireless earbuds with low-latency game mode Moondrop releases Block true wireless earbuds with low-latency game mode Aug 10, 2024 pm 03:31 PM

Moondrop has released the Block true wireless earbuds for audio enthusiasts that sit comfortably in the outer ear. Unlike earbuds jammed into ear canals, the Block does not cause a plugged ear feeling or collect ear wax. The 13 mm driver is enclosed

After 2 months, the humanoid robot Walker S can fold clothes After 2 months, the humanoid robot Walker S can fold clothes Apr 03, 2024 am 08:01 AM

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

ModuleNotFoundError: How to solve Python module not found error? ModuleNotFoundError: How to solve Python module not found error? Jun 25, 2023 pm 09:30 PM

During the development process of Python, we often encounter module not found errors. The specific manifestation of this error is that Python reports one of two errors: ModuleNotFoundError or ImportError when importing the module. This error is very annoying and can cause the program to not run properly, so in this article, we will explore the causes of this error and how to solve it. ModuleNotFoundError and ImportError in Pyth

Java9 new feature Module modular programming method Java9 new feature Module modular programming method May 19, 2023 pm 01:51 PM

In the Java9 version, the Java language introduced a very important concept: module. If you are familiar with the modular management of JavaScript code, you should feel familiar when you see the modular management of Java 9. 1. What is Javamodule? Somewhat similar to packages in Java, modules introduce another level of grouping of Java code. Each such group (module) contains many sub-packages. Declare the folder and its subfolders as a module by adding the file module-info.java to the root of a module's source code file package. The file syntax

How to analyze Drupal configuration How to analyze Drupal configuration May 15, 2023 pm 09:22 PM

Drupal configuration Drupal is an open source PHP content management system with a fairly complex architecture. It also has a strong security model. Thanks to the contributions and maintenance of developers in the community, there is a lot of detailed documentation and methods for strengthening the security configuration of Drupal websites. Remember, Drupal is required to run your website. To protect the entire system from hackers, we need to deal with the entire system. It includes some common server settings, configuration of web servers, PHP and databases. Additionally, any other services on the server need to be configured correctly. It provides tips and key points that can help server and website administrators audit the security of their entire system. We should understand that creating an absolute

What currency is THE? Is THE coin worth investing in? What currency is THE? Is THE coin worth investing in? Feb 21, 2024 pm 03:49 PM

What currency is THE? THE (Tokenized Healthcare Ecosystem) is a digital currency that uses blockchain technology to focus on innovation and reform in the healthcare industry. THE coin's mission is to use blockchain technology to improve the efficiency and transparency of the medical industry and promote more efficient cooperation among all parties, including patients, medical staff, pharmaceutical companies and medical institutions. The Value and Characteristics of THE Coin First of all, THE Coin, as a digital currency, has the advantages of blockchain - decentralization, high security, transparent transactions, etc., allowing participants to trust and rely on this system. Secondly, the uniqueness of THE coin is that it focuses on the medical and health industry, using blockchain technology to transform the traditional medical system and improve

How to solve the problem of 'module fuse not found' when mounting ntfs disk under Linux system? How to solve the problem of 'module fuse not found' when mounting ntfs disk under Linux system? Dec 31, 2023 pm 03:17 PM

1. First confirm the Linux system kernel [root@localhost~]#uname-r-p2.6.18-194.el5i6862. Go to http://sourceforge.net/projects/linux-ntfs/files/ to download the rpm package of the corresponding kernel. If you can't find the exact same one, you can find the closest one. I couldn't find the exact same one. What I downloaded is: kernel-module-ntfs-2.6.18-128.1.1.el5-2.1.27-0.rr.10.11.i686.rpm3. Install the rpm package rpm-ivhkernel -m

Golang learning Web application development based on Drupal Golang learning Web application development based on Drupal Jun 24, 2023 am 11:16 AM

With the development of the mobile Internet, the demand for Web applications continues to increase, and Golang, as an efficient, fast, and safe programming language, has gradually become the new favorite for Web application development. This article will introduce how to use Golang to develop web applications based on Drupal. 1. What is Drupal? Drupal is an open source content management framework based on PHP that can be used to build a variety of web applications, such as e-commerce websites, enterprise portals, and community portals. Dru

See all articles