public function DisclaimerBlock::build in Disclaimer 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/ DisclaimerBlock.php, line 201
Class
- DisclaimerBlock
- Provides a 'DisclaimerBlock' block.
Namespace
Drupal\disclaimer\Plugin\BlockCode
public function build() {
$disclaimer_id = 'disclaimer_' . Html::escape($this->configuration['machine_name']);
// Identify block by class with machine name.
$build = [
'#type' => 'container',
'#attributes' => [
'class' => [
$disclaimer_id,
'disclaimer__noscript',
],
],
];
// Include JS to handle popup and hiding.
$build['#attached']['library'][] = 'disclaimer/disclaimer';
// Pass settings to JS.
$build['#attached']['drupalSettings']['disclaimer'][$disclaimer_id] = [
'redirect' => $this->configuration['redirect'],
'max_age' => Html::escape($this->configuration['max_age']),
'agree' => Html::escape($this->configuration['agree']),
'disagree' => Html::escape($this->configuration['disagree']),
];
// Render disclaimer.
$build['disclaimer_block_disclaimer'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'disclaimer__disclaimer',
],
],
'#markup' => check_markup($this->configuration['disclaimer']['value'], $this->configuration['disclaimer']['format']),
];
// Render popup HTML.
$build['disclaimer_block_challenge'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'disclaimer__challenge',
'hidden',
],
'title' => [
Html::escape($this
->label()),
],
],
'#markup' => check_markup($this->configuration['challenge']['value'], $this->configuration['challenge']['format']),
];
return $build;
}