public function GroupContentTypeForm::submitForm in Group 2.0.x
Same name and namespace in other branches
- 8 src/Entity/Form/GroupContentTypeForm.php \Drupal\group\Entity\Form\GroupContentTypeForm::submitForm()
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.
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 EntityForm::submitForm
File
- src/
Entity/ Form/ GroupContentTypeForm.php, line 126
Class
- GroupContentTypeForm
- Form controller for group content type forms.
Namespace
Drupal\group\Entity\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\group\Entity\GroupContentTypeInterface $group_content_type */
$group_content_type = $this
->getEntity();
$group_type = $group_content_type
->getGroupType();
$plugin = $this
->getRelationPlugin();
$plugin
->submitConfigurationForm($form, $form_state);
// Remove button and internal Form API values from submitted values.
$form_state
->cleanValues();
// Extract the values as configuration that should be saved.
$config = $form_state
->getValues();
// If we are on an 'add' form, we create the group content type using the
// plugin configuration submitted using this form.
if ($this->operation == 'add') {
/** @var \Drupal\group\Entity\Storage\GroupContentTypeStorageInterface $storage */
$storage = $this->entityTypeManager
->getStorage('group_content_type');
$storage
->createFromPlugin($group_type, $plugin
->getPluginId(), $config)
->save();
$this
->messenger()
->addStatus($this
->t('The content plugin was installed on the group type.'));
}
else {
$group_content_type
->updateContentPlugin($config);
$this
->messenger()
->addStatus($this
->t('The content plugin configuration was saved.'));
}
$form_state
->setRedirect('entity.group_type.content_plugins', [
'group_type' => $group_type
->id(),
]);
}