You are here

public static function DomainElementManager::submitEntityForm in Domain Access 8

Submit function for handling hidden values from a form.

On form submit, loop through the hidden form values and add those to the entity being saved.

No return value. Hidden values are added to the field values directly.

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

Overrides DomainElementManagerInterface::submitEntityForm

File

domain/src/DomainElementManager.php, line 116

Class

DomainElementManager
Generic base class for handling hidden field options.

Namespace

Drupal\domain

Code

public static function submitEntityForm(array &$form, FormStateInterface $form_state) {
  $fields = $form_state
    ->getValue('domain_hidden_fields');
  foreach ($fields as $field) {
    $entity_values = [];
    $values = $form_state
      ->getValue($field . '_disallowed');
    if (!empty($values)) {
      $info = $form_state
        ->getBuildInfo();
      $node = $form_state
        ->getFormObject()
        ->getEntity();
      $entity_values = $form_state
        ->getValue($field);
    }
    if (is_array($values)) {
      foreach ($values as $value) {
        $entity_values[]['target_id'] = $value;
      }
    }
    else {
      $entity_values[]['target_id'] = $values;
    }

    // Prevent a fatal error caused by passing a NULL value.
    // See https://www.drupal.org/node/2841962.
    if (!empty($entity_values)) {
      $form_state
        ->setValue($field, $entity_values);
    }
  }
}