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小节:

评论 (写第一个评论)