function EntityFormDisplay::buildForm
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm()
- 10 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm()
- 11.x core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm()
Overrides EntityFormDisplayInterface::buildForm
File
-
core/
lib/ Drupal/ Core/ Entity/ Entity/ EntityFormDisplay.php, line 169
Class
- EntityFormDisplay
- Configuration entity that contains widget options for all components of a entity form in a given form mode.
Namespace
Drupal\Core\Entity\EntityCode
public function buildForm(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state) {
// Set #parents to 'top-level' by default.
$form += [
'#parents' => [],
];
// Let each widget generate the form elements.
foreach ($this->getComponents() as $name => $options) {
if ($widget = $this->getRenderer($name)) {
$items = $entity->get($name);
$items->filterEmptyItems();
$form[$name] = $widget->form($items, $form, $form_state);
$form[$name]['#access'] = $items->access('edit');
// Assign the correct weight. This duplicates the reordering done in
// processForm(), but is needed for other forms calling this method
// directly.
$form[$name]['#weight'] = $options['weight'];
// Associate the cache tags for the field definition & field storage
// definition.
$field_definition = $this->getFieldDefinition($name);
$this->renderer
->addCacheableDependency($form[$name], $field_definition);
$this->renderer
->addCacheableDependency($form[$name], $field_definition->getFieldStorageDefinition());
}
}
// Associate the cache tags for the form display.
$this->renderer
->addCacheableDependency($form, $this);
// Add a process callback so we can assign weights and hide extra fields.
$form['#process'][] = [
$this,
'processForm',
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.