You are here

public function NodeFormBlock::build in Form Block 8

Same name and namespace in other branches
  1. 2.0.x 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 136

Class

NodeFormBlock
Provides a block for node forms.

Namespace

Drupal\formblock\Plugin\Block

Code

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);
  return $build;
}