public function AssignmentConfigureForm::submitForm in Features 8.4
Same name and namespace in other branches
- 8.3 modules/features_ui/src/Form/AssignmentConfigureForm.php \Drupal\features_ui\Form\AssignmentConfigureForm::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
- modules/
features_ui/ src/ Form/ AssignmentConfigureForm.php, line 401
Class
- AssignmentConfigureForm
- Configures the configuration assignment methods for this site.
Namespace
Drupal\features_ui\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$enabled_methods = array_filter($form_state
->getValue('enabled'));
ksort($enabled_methods);
$method_weights = $form_state
->getValue('weight');
ksort($method_weights);
$machine_name = $form_state
->getValue([
'bundle',
'machine_name',
]);
// If this is a new bundle, create it.
if ($form_state
->getValue([
'bundle',
'bundle_select',
]) == self::NEW_BUNDLE_SELECT_VALUE) {
$bundle = $this->assigner
->createBundleFromDefault($machine_name);
}
else {
$bundle = $this->assigner
->loadBundle();
$old_name = $bundle
->getMachineName();
$new_name = $form_state
->getValue([
'bundle',
'machine_name',
]);
if ($old_name != $new_name) {
$bundle = $this->assigner
->renameBundle($old_name, $new_name);
}
}
$bundle
->setName($form_state
->getValue([
'bundle',
'name',
]));
$bundle
->setDescription($form_state
->getValue([
'bundle',
'description',
]));
$bundle
->setEnabledAssignments(array_keys($enabled_methods));
$bundle
->setAssignmentWeights($method_weights);
$bundle
->setIsProfile($form_state
->getValue([
'bundle',
'is_profile',
]));
$bundle
->setProfileName($form_state
->getValue([
'bundle',
'profile_name',
]));
$bundle
->save();
$this->assigner
->setBundle($bundle);
$this->assigner
->setCurrent($bundle);
$form_state
->setRedirect('features.assignment');
$this
->messenger()
->addStatus($this
->t('Package assignment configuration saved.'));
}