찾다
php教程php手册Explore block module in 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;

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 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.