Drupal8模块开发-在区块显示中使用配置信息

翻译:长风Drupal开发

原文:https://www.drupal.org/docs/8/creating-custom-modules/use-config-in-block-display

为了在Drupal8开发的区块实例中使用配置信息,我们需要修改HelloBlock类的build()方法;

/**
   * {@inheritdoc}
   */  
  public function build() {
    $config = $this->getConfiguration();

    if (!empty($config['hello_block_name'])) {
      $name = $config['hello_block_name'];
    }
    else {
      $name = $this->t('to no one');
    }
    return array(
      '#markup' => $this->t('Hello @name!', array (
          '@name' => $name,
        )
      ),
    );
  }