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 才能监测到这个块。

评论 (写第一个评论)