function EntityFormDisplay::processForm

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::processForm()
  2. 8.9.x core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::processForm()
  3. 10 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::processForm()

Process callback: assigns weights and hides extra fields.

See also

\Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm()

File

core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php, line 218

Class

EntityFormDisplay
Configuration entity.

Namespace

Drupal\Core\Entity\Entity

Code

public function processForm($element, FormStateInterface $form_state, $form) {
    // Assign the weights configured in the form display.
    foreach ($this->getComponents() as $name => $options) {
        if (isset($element[$name])) {
            $element[$name]['#weight'] = $options['weight'];
        }
    }
    // Hide extra fields.
    $extra_fields = \Drupal::service('entity_field.manager')->getExtraFields($this->targetEntityType, $this->bundle);
    $extra_fields = $extra_fields['form'] ?? [];
    foreach ($extra_fields as $extra_field => $info) {
        if (!$this->getComponent($extra_field)) {
            $element[$extra_field]['#access'] = FALSE;
        }
    }
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.