8.2 创建区块

Drupal8龬龩龧龤龢龠龟PSR-4龍龋龊

  • 龉hello_world龤龢齼齻齺龤龢 src\Plugin\Block

  • 龉Block龤龢齼齻齺ExampleBlock.php齔齒齏齋齈齇齼齄

<?php

namespace Drupal\hello_world\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'Hello' Block
 *
 * @Block(
 *   id = "hello_block",
 *   admin_label = @Translation("Hello block"),
 * )
 */

class HelloBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    return array(
      '#markup' => $this->t('Hello, World!'),
    );
  }
}

鼂黾龬黻黷黵黳黯黭@Block黫黩

  • id: 黢黠ID
  • admin_label: 黜黛黙黖龬黓黏龍黎

{@inheritdoc}黫黍黌黋黉黇黅黁麾麻龬黫黩龊

麸麴麱麮麬麩黭麨麤麡麞麛麘龬麖麒-build齏麎麌麋麨麤麈麇麅龬麁鹿龊

鹼鹹 admin/stucture/block齏龉鹶鹲黢鹱齋鹰鹯"鹭鹩黢黠"鹥鹣齏龉鹡鹟龬鹛鹚鹖齋鹓麈鹒鹎鹍麸麤鹉黢黠龊

麸鹅麨麤鹁鸿龬麈麛鸻黅黁龬黢黠鹓鸺鸷黭龊

本书共79小节:

评论 (写第一个评论)