You are here

public function DomainEntitySettings::submitForm in Domain Access Entity 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/DomainEntitySettings.php, line 246

Class

DomainEntitySettings
Provides a form to configure domain fields mappings.

Namespace

Drupal\domain_entity\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $entity_type_id = $this->entityType
    ->id();
  $bundles = array_keys($this
    ->getBundles($entity_type_id));

  // @todo Use batch for operations.
  foreach ($bundles as $bundle) {
    if (empty($values[$bundle . '_enable'])) {
      if ($field = $this->mapper
        ->loadField($entity_type_id, $bundle)) {
        $field
          ->delete();
      }
    }
    else {
      if ($field = $this->mapper
        ->loadField($entity_type_id, $bundle)) {

        // Update settings.
        $field
          ->setThirdPartySetting('domain_entity', 'domains', array_filter($values[$bundle . '_domains']));
        $field
          ->setThirdPartySetting('domain_entity', 'behavior', $values[$bundle . '_behavior']);
        $field
          ->save();
      }
      else {
        $this->mapper
          ->addDomainField($entity_type_id, $bundle);
      }
    }
  }
}