public function ConditionalFieldEditForm::submitForm in Conditional Fields 4.x
Same name and namespace in other branches
- 8 src/Form/ConditionalFieldEditForm.php \Drupal\conditional_fields\Form\ConditionalFieldEditForm::submitForm()
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
1 call to ConditionalFieldEditForm::submitForm()
- ConditionalFieldEditFormTab::submitForm in src/
Form/ ConditionalFieldEditFormTab.php - Form submission handler.
1 method overrides ConditionalFieldEditForm::submitForm()
- ConditionalFieldEditFormTab::submitForm in src/
Form/ ConditionalFieldEditFormTab.php - Form submission handler.
File
- src/
Form/ ConditionalFieldEditForm.php, line 325
Class
- ConditionalFieldEditForm
- An edit form for conditional fields.
Namespace
Drupal\conditional_fields\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->cleanValues()
->getValues();
$uuid = $values['uuid'];
$entity_type = $values['entity_type'];
$bundle = $values['bundle'];
/** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $entity */
$entity = $this->entityTypeManager
->getStorage('entity_form_display')
->load("{$entity_type}.{$bundle}.default");
if (!$entity) {
return;
}
$field_names = explode('-', $values['field_name']);
foreach ($field_names as $field_name) {
$field = $entity
->getComponent($field_name);
$settings =& $field['third_party_settings']['conditional_fields'][$uuid]['settings'];
$dependee = $field['third_party_settings']['conditional_fields'][$uuid]['dependee'];
$exclude_fields = [
'entity_type',
'bundle',
'field_name',
'uuid',
];
foreach ($values as $key => $value) {
if (in_array($key, $exclude_fields) || empty($value)) {
continue;
}
else {
$settings[$key] = $value;
}
}
if (isset($settings['reset']) && !empty($settings['reset'])) {
$settings['reset'] = $values['reset'];
}
else {
$settings['reset'] = 0;
}
if ($settings['effect'] == 'show') {
$settings['effect_options'] = [];
}
// Set field value.
if (isset($settings[$dependee]) && !empty($settings[$dependee])) {
// Get and save value as string with timezone.
$value =& $settings[$dependee];
if (!empty($value[0]['value']) && is_object($value[0]['value']) && $value[0]['value'] instanceof DrupalDateTime) {
foreach ($value as $delta => $date) {
if (!empty($date['value'])) {
// Need to find a solution to handle both datetime and date types.
$value[$delta]['value'] = $date['value']
->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
}
}
}
$settings['value_form'] = $settings[$dependee];
unset($settings[$dependee]);
}
$entity
->setComponent($field_name, $field);
}
$entity
->save();
$parameters = [
'entity_type' => $values['entity_type'],
'bundle' => $values['bundle'],
];
$form_state
->setRedirect($this->redirectPath, $parameters);
}