public function FieldGroupAddForm::submitForm in Field Group 8
Same name and namespace in other branches
- 8.3 src/Form/FieldGroupAddForm.php \Drupal\field_group\Form\FieldGroupAddForm::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
File
- src/
Form/ FieldGroupAddForm.php, line 223
Class
- FieldGroupAddForm
- Provides a form for adding a fieldgroup to a bundle.
Namespace
Drupal\field_group\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->get('step') == 'formatter') {
$form_state
->set('step', 'configuration');
$form_state
->set('group_label', $form_state
->getValue('label'));
$form_state
->set('group_name', $form_state
->getValue('group_name'));
$form_state
->set('group_formatter', $form_state
->getValue('group_formatter'));
$form_state
->setRebuild();
}
else {
$new_group = (object) array(
'group_name' => $form_state
->get('group_name'),
'entity_type' => $this->entityTypeId,
'bundle' => $this->bundle,
'mode' => $this->mode,
'context' => $this->context,
'children' => [],
'parent_name' => '',
'weight' => 20,
'format_type' => $form_state
->get('group_formatter'),
);
$new_group->format_settings = $form_state
->getValue('format_settings');
$new_group->label = $new_group->format_settings['label'];
unset($new_group->format_settings['label']);
$new_group->format_settings += _field_group_get_default_formatter_settings($form_state
->get('group_formatter'), $this->context);
field_group_group_save($new_group);
// Store new group information for any additional submit handlers.
$groups_added = $form_state
->get('groups_added');
$groups_added['_add_new_group'] = $new_group->group_name;
drupal_set_message(t('New group %label successfully created.', array(
'%label' => $new_group->label,
)));
$form_state
->setRedirectUrl(FieldgroupUi::getFieldUiRoute($new_group));
\Drupal::cache()
->invalidate('field_groups');
}
}