public function SimpleBlockBlock::build in Simple Block 8
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ SimpleBlockBlock.php, line 92
Class
- SimpleBlockBlock
- Defines a generic custom block config type.
Namespace
Drupal\simple_block\Plugin\BlockCode
public function build() : array {
if (!($simple_block = $this
->getEntity())) {
return [
'#markup' => $this
->t('Simple block with ID %id does not exist. <a href=":url">Add simple block</a>.', [
'%id' => $this
->getDerivativeId(),
':url' => Url::fromRoute('simple_block.form_add'),
]),
'#access' => $this->currentUser
->hasPermission('administer blocks'),
];
}
$content = $simple_block
->getContent();
return [
'#type' => 'processed_text',
'#text' => \Drupal::token()
->replace($content['value']),
'#format' => $content['format'],
'#contextual_links' => [
'simple_block' => [
'route_parameters' => [
'simple_block' => $simple_block
->id(),
],
],
],
];
}