首页 php教程 php手册 Explore block module in Drupal

Explore block module in Drupal

Jun 13, 2016 am 10:53 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);  

  }  

}  

 

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系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.能量晶体解释及其做什么(黄色晶体)
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
1 个月前 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 真无线耳机,可舒适地佩戴在外耳中。与塞入耳道的耳塞不同,Block 不会造成耳朵堵塞的感觉或积聚耳垢。随附 13 毫米驱动器

2 个月不见,人形机器人 Walker S 会叠衣服了 2 个月不见,人形机器人 Walker S 会叠衣服了 Apr 03, 2024 am 08:01 AM

机器之能报道编辑:吴昕国内版的人形机器人+大模型组队,首次完成叠衣服这类复杂柔性材料的操作任务。随着融合了OpenAI多模态大模型的Figure01揭开神秘面纱,国内同行的相关进展一直备受关注。就在昨天,国内"人形机器人第一股"优必选发布了人形机器人WalkerS深入融合百度文心大模型后的首个Demo,展示了一些有趣的新功能。现在,得到百度文心大模型能力加持的WalkerS是这个样子的。和Figure01一样,WalkerS没有走动,而是站在桌子后面完成一系列任务。它可以听从人类的命令,折叠衣物

ModuleNotFoundError:如何解决Python找不到模块错误? ModuleNotFoundError:如何解决Python找不到模块错误? Jun 25, 2023 pm 09:30 PM

在Python的开发过程中,经常会遇到找不到模块的错误。这个错误的具体表现就是Python在导入模块的时候报出ModuleNotFoundError或者ImportError这两个错误之一。这种错误很困扰,会导致程序无法正常运行,因此在这篇文章里,我们将会探究这个错误的原因及其解决方法。ModuleNotFoundError和ImportError在Pyth

Java9新特性Module模块化编程的方法 Java9新特性Module模块化编程的方法 May 19, 2023 pm 01:51 PM

在Java9版本中Java语言引入了一个非常重要的概念:模块(module)。如果对javascript代码模块化管理比较熟悉的小伙伴,看到Java9的模块化管理,应该有似曾相识的感觉。一、什么是Javamodule?与Java中的package有些类似,module引入了Java代码分组的另一个级别。每个这样的分组(module)都包含许多子package包。通过在一个模块的源代码文件package的根部,添加文件module-info.java来声明该文件夹及其子文件夹为一个模块。该文件语法

如何解决Linux系统下挂载ntfs盘时出现'module fuse not found'的问题? 如何解决Linux系统下挂载ntfs盘时出现'module fuse not found'的问题? Dec 31, 2023 pm 03:17 PM

1.首先确认一下Linux系统内核[root@localhost~]#uname-r-p2.6.18-194.el5i6862.到http://sourceforge.net/projects/linux-ntfs/files/下载对应内核的rpm包如果找不到完全一致的,可以找最相近的。我的就没有找到完全一致的,我下载的是:kernel-module-ntfs-2.6.18-128.1.1.el5-2.1.27-0.rr.10.11.i686.rpm3.安装rpm包rpm-ivhkernel-m

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

Drupal配置Drupal是一个开源的PHP内容管理系统,具有相当复杂的架构。它还具有强大的安全模型。感谢开发人员在社区的贡献和维护,所以有很多详细的文档和有关加强Drupal网站安全配置的方法。切记,Drupal是运行网站所需的一部分。为了保护整个系统免受黑客攻击,我们需要处理整套系统。它包括一些常见的服务器设置,Web服务器的配置,PHP和数据库。此外,服务器上的任何其他服务都需要正确配置。它提供了一些提示和关键点,可以帮助服务器和网站管理员审核整个系统的安全性。我们应该明白,打造一个绝对

THE是什么币种,THE币值得投资吗? THE是什么币种,THE币值得投资吗? Feb 21, 2024 pm 03:49 PM

THE是什么币种?THE(TokenizedHealthcareEcosystem)是一种数字货币,利用区块链技术,专注于医疗健康行业的创新和改革。THE币的使命是利用区块链技术提高医疗行业的效率和透明度,推动各方之间更高效的合作,包括患者、医护人员、制药公司和医疗机构。THE币的价值和特点首先,THE币作为一种数字货币,具备了区块链的优势——去中心化、安全性高、交易透明等,让参与者能够信任和依赖这个系统。其次,THE币的独特之处在于它专注于医疗健康行业,借助区块链技术改造了传统医疗体系,提升了

如何通过PHP-FPM优化提高Drupal网站的性能 如何通过PHP-FPM优化提高Drupal网站的性能 Oct 05, 2023 am 10:09 AM

如何通过PHP-FPM优化提高Drupal网站的性能摘要:Drupal是一个功能强大的内容管理系统,但在处理大量请求时可能会出现性能瓶颈。本文将介绍如何使用PHP-FPM来优化Drupal网站的性能,包括调整PHP-FPM的配置参数、使用进程管理器和使用缓存等方法,同时给出具体的代码示例。调整PHP-FPM的配置参数提高PHP-FPM的最大进程数和最大请求数

See all articles