public function AddForm::submitForm in Linkit 8.4
Same name in this branch
- 8.4 src/Form/Attribute/AddForm.php \Drupal\linkit\Form\Attribute\AddForm::submitForm()
- 8.4 src/Form/Matcher/AddForm.php \Drupal\linkit\Form\Matcher\AddForm::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/ Attribute/ AddForm.php, line 106 - Contains \Drupal\linkit\Form\Attribute\AddForm.
Class
- AddForm
- Provides a form to apply attributes to a profile.
Namespace
Drupal\linkit\Form\AttributeCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->cleanValues();
/** @var \Drupal\linkit\AttributeInterface $plugin */
$plugin = $this->manager
->createInstance($form_state
->getValue('plugin'));
$plugin_id = $this->linkitProfile
->addAttribute($plugin
->getConfiguration());
$this->linkitProfile
->save();
$this
->logger('linkit')
->notice('Added %label attribute to the @profile profile.', [
'%label' => $this->linkitProfile
->getAttribute($plugin_id)
->getLabel(),
'@profile' => $this->linkitProfile
->label(),
]);
$is_configurable = $plugin instanceof ConfigurableAttributeInterface;
if ($is_configurable) {
$form_state
->setRedirect('linkit.attribute.edit', [
'linkit_profile' => $this->linkitProfile
->id(),
'plugin_instance_id' => $plugin_id,
]);
}
else {
drupal_set_message($this
->t('Added %label attribute.', [
'%label' => $plugin
->getLabel(),
]));
$form_state
->setRedirect('linkit.attributes', [
'linkit_profile' => $this->linkitProfile
->id(),
]);
}
}