public function DomainEntityUi::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 ConfigFormBase::submitForm
File
- src/
Form/ DomainEntityUi.php, line 116
Class
- DomainEntityUi
- Provides a form to configure domain field mappings.
Namespace
Drupal\domain_entity\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('domain_entity.settings');
$config
->set('bypass_access_conditions', $form_state
->getValue('bypass_access_conditions'))
->save();
$entity_types = $form_state
->getValue('entity_types');
$all_types = $this->mapper
->getEntityTypes();
$enabled_types = $this->mapper
->getEnabledEntityTypes();
$results = [
'create' => [],
'delete' => [],
];
foreach ($all_types as $entity_type_id => $entity_type) {
if (empty($entity_types[$entity_type_id])) {
if (isset($enabled_types[$entity_type_id])) {
$results['delete'][] = $entity_type_id;
}
}
elseif (!isset($enabled_types[$entity_type_id])) {
$results['create'][] = $entity_type_id;
}
}
// Process results.
// @todo Add batch to create/delete field storage configs.
foreach ($results as $action => $types) {
if ($action == 'delete') {
foreach ($types as $type) {
$this->mapper
->deleteFieldStorage($type);
}
}
elseif ($action == 'create') {
foreach ($types as $type) {
$this->mapper
->createFieldStorage($type);
}
}
}
parent::submitForm($form, $form_state);
}