首頁 後端開發 php教程 Explore block module in Drupal_PHP教程

Explore block module in Drupal_PHP教程

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...
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Moondrop 發布 Block 真無線耳機,具有低延遲遊戲模式 Moondrop 發布 Block 真無線耳機,具有低延遲遊戲模式 Aug 10, 2024 pm 03:31 PM

Moondrop 發布 Block 真無線耳機,具有低延遲遊戲模式

2 個月不見,人形機器人 Walker S 會摺衣服了 2 個月不見,人形機器人 Walker S 會摺衣服了 Apr 03, 2024 am 08:01 AM

2 個月不見,人形機器人 Walker S 會摺衣服了

ModuleNotFoundError:如何解決Python找不到模組錯誤? ModuleNotFoundError:如何解決Python找不到模組錯誤? Jun 25, 2023 pm 09:30 PM

ModuleNotFoundError:如何解決Python找不到模組錯誤?

Java9新特性Module模組化程式設計的方法 Java9新特性Module模組化程式設計的方法 May 19, 2023 pm 01:51 PM

Java9新特性Module模組化程式設計的方法

如何分析Drupal配置 如何分析Drupal配置 May 15, 2023 pm 09:22 PM

如何分析Drupal配置

THE是什麼幣種,THE幣值得投資嗎? THE是什麼幣種,THE幣值得投資嗎? Feb 21, 2024 pm 03:49 PM

THE是什麼幣種,THE幣值得投資嗎?

如何解決Linux系統下掛載ntfs磁碟時出現'module fuse not found'的問題? 如何解決Linux系統下掛載ntfs磁碟時出現'module fuse not found'的問題? Dec 31, 2023 pm 03:17 PM

如何解決Linux系統下掛載ntfs磁碟時出現'module fuse not found'的問題?

Golang學習之基於Drupal的網路應用程式開發 Golang學習之基於Drupal的網路應用程式開發 Jun 24, 2023 am 11:16 AM

Golang學習之基於Drupal的網路應用程式開發

See all articles