class EntityFormViewBuilder in Twig Tweak 3.1.x
Same name and namespace in other branches
- 3.x src/View/EntityFormViewBuilder.php \Drupal\twig_tweak\View\EntityFormViewBuilder
Entity form view builder.
Hierarchy
- class \Drupal\twig_tweak\View\EntityFormViewBuilder
Expanded class hierarchy of EntityFormViewBuilder
1 string reference to 'EntityFormViewBuilder'
1 service uses EntityFormViewBuilder
File
- src/
View/ EntityFormViewBuilder.php, line 13
Namespace
Drupal\twig_tweak\ViewView source
class EntityFormViewBuilder {
/**
* The entity form builder service.
*
* @var \Drupal\Core\Entity\EntityFormBuilderInterface
*/
protected $entityFormBuilder;
/**
* Constructs an EntityFormViewBuilder object.
*/
public function __construct(EntityFormBuilderInterface $entity_form_builder) {
$this->entityFormBuilder = $entity_form_builder;
}
/**
* Gets the built and processed entity form for the given entity type.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param string $form_mode
* (optional) The mode identifying the form variation to be returned.
* @param bool $check_access
* (optional) Indicates that access check is required.
*
* @return array
* The processed form for the given entity type and form mode.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityFormViewBuilder:: |
protected | property | The entity form builder service. | |
EntityFormViewBuilder:: |
public | function | Gets the built and processed entity form for the given entity type. | |
EntityFormViewBuilder:: |
public | function | Constructs an EntityFormViewBuilder object. |