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

评论 (写第一个评论)