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

评论 (写第一个评论)