You are here

public function EntityFormDisplay::processForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 201
Contains \Drupal\Core\Entity\Entity\EntityFormDisplay.

Class

EntityFormDisplay
Configuration entity that contains widget options for all components of a entity form in a given form mode.

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::entityManager()
    ->getExtraFields($this->targetEntityType, $this->bundle);
  $extra_fields = isset($extra_fields['form']) ? $extra_fields['form'] : array();
  foreach ($extra_fields as $extra_field => $info) {
    if (!$this
      ->getComponent($extra_field)) {
      $element[$extra_field]['#access'] = FALSE;
    }
  }
  return $element;
}