You are here

public function EntityFormViewBuilder::build in Twig Tweak 3.1.x

Same name and namespace in other branches
  1. 3.x src/View/EntityFormViewBuilder.php \Drupal\twig_tweak\View\EntityFormViewBuilder::build()

Gets the built and processed entity form for the given entity type.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

string $form_mode: (optional) The mode identifying the form variation to be returned.

bool $check_access: (optional) Indicates that access check is required.

Return value

array The processed form for the given entity type and form mode.

File

src/View/EntityFormViewBuilder.php, line 42

Class

EntityFormViewBuilder
Entity form view builder.

Namespace

Drupal\twig_tweak\View

Code

public function build(EntityInterface $entity, string $form_mode = 'default', bool $check_access = TRUE) : array {
  $build = [];
  $operation = $entity
    ->isNew() ? 'create' : 'update';
  $access = $check_access ? $entity
    ->access($operation, NULL, TRUE) : AccessResult::allowed();
  if ($access
    ->isAllowed()) {
    $build = $this->entityFormBuilder
      ->getForm($entity, $form_mode);
  }
  CacheableMetadata::createFromRenderArray($build)
    ->merge(CacheableMetadata::createFromObject($entity))
    ->merge(CacheableMetadata::createFromObject($access))
    ->applyTo($build);
  return $build;
}