public function WebformBlock::build in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/Block/WebformBlock.php \Drupal\webform\Plugin\Block\WebformBlock::build()
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/ WebformBlock.php, line 181
Class
- WebformBlock
- Provides a 'Webform' block.
Namespace
Drupal\webform\Plugin\BlockCode
public function build() {
$webform = $this
->getWebform();
if (!$webform) {
if (strpos($this->routeMatch
->getRouteName(), 'layout_builder.') === 0) {
return [
'#markup' => $this
->t('The webform (@webform) is broken or missing.', [
'@webform' => $this->configuration['webform_id'],
]),
];
}
else {
return [];
}
}
$build = [
'#type' => 'webform',
'#webform' => $webform,
'#default_data' => WebformYaml::decode($this->configuration['default_data']),
];
// If redirect, set the #action property on the form.
if ($this->configuration['redirect']) {
$build['#action'] = $this
->getWebform()
->toUrl()
->setOption('query', $this->requestStack
->getCurrentRequest()->query
->all())
->toString();
}
return $build;
}