滚动
在区块中使用配置
为了在区块实例中使用配置,我们可以修改 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 [
'#markup' => $this->t('Hello @name!', [
'@name' => $name,
]),
];
}