public function EntityForm::build in Flexiform 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/ EntityForm.php, line 132
Class
- EntityForm
- Provides a block to see an entity form.
Namespace
Drupal\flexiform\Plugin\BlockCode
public function build() {
// @var $entity \Drupal\Core\Entity\EntityInterface
$entity = $this
->getContextValue('entity');
$definition = $this
->getPluginDefinition();
if ($entity
->bundle() !== $definition['bundle']) {
return;
}
$entity_form_display = EntityFormDisplay::collectRenderDisplay($entity, $definition['form_mode']);
$form_object = $this->flexiformManager
->getFormObject($entity_form_display, [
$entity_form_display
->getBaseEntityNamespace() => $entity,
]);
foreach ($entity_form_display
->getFormEntityConfig() as $namespace => $configuration) {
if ($configuration['plugin'] == 'provided' && ($provided_entity = $this
->getContextValue($namespace))) {
$provided[$namespace] = $provided_entity;
}
}
$form_state = new FormState();
$form_state
->set('form_entity_provided', $provided['form_entity_provided']);
return $this->formBuilder
->buildForm($form_object, $form_state);
}