public function NodeFormBlock::build in Form Block 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Block/NodeFormBlock.php \Drupal\formblock\Plugin\Block\NodeFormBlock::build()
Implements \Drupal\block\BlockBase::build().
Overrides BlockPluginInterface::build
File
- src/
Plugin/ Block/ NodeFormBlock.php, line 178
Class
- NodeFormBlock
- Provides a block for node forms.
Namespace
Drupal\formblock\Plugin\BlockCode
public function build() {
$build = [];
$node_type = NodeType::load($this->configuration['type']);
if ($this->configuration['show_help']) {
$build['help'] = [
'#markup' => !empty($node_type
->getHelp()) ? '<p>' . Xss::filterAdmin($node_type
->getHelp()) . '</p>' : '',
];
}
$node = $this->entityTypeManager
->getStorage('node')
->create([
'type' => $node_type
->id(),
]);
$build['form'] = $this->entityFormBuilder
->getForm($node, $this->configuration['form_mode']);
return $build;
}