2.1 区块与配置

龺龹龸龶龵龱龵龭龪龩龨龥龣龠龜龚龗龖龕龓龒龐龏龒 Drupal 8 齻齸齵齱龥齭龖齬齪龨齨齧齣齢

Drupal 8 齻龥 龨 API 齘龵龕齖齓龨齐齍 齊龖齈plugins鼹 鼶齍鼳鼱齈entities鼹齢

Drupal 8 齻龥龨鼧鼣鼡鼠 API 齭鼝齬

  • 龨齊龖 API 齬鼜龠鼛鼗鼓鼒齱龥 API
  • 龨鼳鼱 API 齬鼎鼊龨龥鼉鼈齨鼓鼆鼄鼁黽

黼黺黷黴齖齓龨齍鼓黲黰黬龥鼳鼱齨黪齓黨齱黤龥齊龖黣黠齈 change record here 鼹齢

鼶黺黷黴龺龹鼓黗黔龪黤龥黓黑龕黎黋黲黰龕黨齱黊黆黂黀麿龏麽龹齢

齖齓鼜龠齪龨鼓黗黆麹麶麵齓麱龠齪麭齈regions鼹麩龕黼齓 Drupal 8 麨麧齍黊鼓黗龥齢
鼳麣麟齖齓齍鼓黗黔龪黆鼜龠龨龥麱龠鼳麛龵齢
麗鼶鼓黗麔麓 UI 麎鼜龠龨黆麹麋齓黊黆龥齪麭龕黊麈麆麃麁麀齢

鹿鹼龺龹鹺黨齱 Examples 鹰鹭龥 block_example 龩龨齢

本课学习内容

  • 黔龪 examples/block_example 龩龨
  • 鹠鹝 Drupal 8 齻龥鹛龱
  • 鹚鹘鹖鹔黨齱 Drupal GUI 鹏黋齪龨
  • 鹎鹍 Form API
  • 鹚鹘鹖鹔黨齱 Form API
  • 鹈鹅鹖鹔黔龪鹁鸿齧齣龥齪龨齨鸻鸹

Drupal 8 区块

黊龜黨齱 4 龠鸴鸰黑鸮齪龨龵齈Drupal 7 齻麗龜鸩黼鸨鸤鼹龕齊龖黣黠鸢鸟黗龒麩鸜齬

  • 鼜龠齪龨鼜龠鸛龖
  • 鹖鸘麗鸔黔龪黤齪龨龕鼓黗鸐龓拷鸎鸋鸉鸆麨麧齪龨鸛龖龕鸄鸂鷿黤齪龨齢
  • 黗鷼鸉鸆齪龨鷸龚鼎鼊鼉鷶黊黆鼉鼈龥鷳龠鷰鷮龕鷬黼鷪鷰鷮鼓鷦齓鼣龠鸛龖鷢齢
    齖齓齪龨麩鸜鷟齓鼜龠鸛龖麩齢
  • 鷞鸿鷛鷙鷗齓鷔龠鸛龖
  • 麗黊鷸龚鷒鷏鹔 info 鸛龖鷋鷊麗龥鷇鷅鷄龕鷃鷂麽麈鷁鶾鶽黋鶼齢
  • 齪龨鶹鶵鶲鷁鶱鶰齓鼜龠鼛鼗鸛龖麩

创建一个简单的区块

Example 鹰鹭鸿龠 block_example 龩龨龕齓 src/Plugin/Block 鸛龖鶫麩鸿 3 龠麛鸰龕鼠鶨鶦麵 3 鶤黊黆齪龨齢
龺龹龏龒齸鶢齣龥鷔龠齬黔龪鼜龠鶟鸿鷏鹔麩鸜龥鶞龨齢

鶛鶘齓 examples 鸛龖鶫麩黔龪黤龩龨 block_example齈黔龪龩龨黂鶔鶑鶐鶌 麟鼜鹼 鼹齢
麨鶉齓 block_example 鹭鶈龒黔龪 src/Plugin/Block 鹭鶈齢
齸鶉齓 Block 鹭鶈黔龪 ExampleEmptyBlock.php 鸛龖龕麋鼈鶁鵿龕鼆鵻鵹麩鸜齪齢

<?php

namespace Drupal\block_example\Plugin\Block;
use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'Example: empty block' block.
 *
 * @Block(
 *   id = "example_empty",
 *   admin_label = @Translation("Example: empty block")
 * )
 */
class ExampleEmptyBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    return [
      '#type' => 'markup',
      '#markup' => '',
    ];
  }

}

类和注解

鷞鸿鷇鵶鵴龥麹鵱龜鸩黑鸮鵰黲鶞鵮龕麨鶉龺龹鵪鶦 BlockBase 黔龪鷇 ExampleEmptyBlock 齢 齓黼龠鷇鷢龺龹鼓黗黨齱 Drupal 8 鵩鵨龥鹛龱齢

麔齵 PHP 鹛龱齍鼜黰鶾鵡鵝龥鹛鵚鸛鹿龕麽鵖鵓鷇鸛龖鹛鵏鵍鵌齨鵉鷮鵇龥鶾鶽麆齖齢

麟鸹鵄 1 齭鹛龱齍鴼鴸 Drupal 龺龹龚黔龪鼜龠 id 鷂 example_empty 齨 鴷鼊 label 鷂 鴶Example: empty block鴮龥齪龨齈@Block鼹齢鴫鷬黼龠鴷鼊 label 齓黨齱麨麧龚龶麓鴨鴦黣黠鼎鼊齢

齓鴥鴣鷇鷰鷮麹鼓黗黨齱 {@inheritdoc} 鹛龱龕麽鴼鴸黣黠黼鷢黨齱鴗鷇龥鹛龱齢

龺龹鼳齖龵鼜龠 build() 黂鶔龕黼齍鼜龠齸鼒龚鸋齵齱龥黂鶔龕麽麈鴑鴎鼜龠鼓鴌鴈鷮齭齈齱鷶龨鴄鴃鼹齢

鳿鳾 block_example 龩龨鷁鳻鳺龕鳹鶞鳵鳲齢
齓龨鳱鼈鸻齈 /admin/structure/block 鼹龥鷏黺齪麭麩鳭鳪鴶麋鼈齪龨鴮鳨鳦龕鳥鴃龥鳣鳟鳜麩麗麈龏鷿黼龠黤齪龨齢

注意: 只有书写了正确的注解后 Drupal 才能监测到这个块。

评论 (写第一个评论)