public function PostForm::save in Open Social 10.2.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.2 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.3 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.4 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.5 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.6 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.7 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 8.8 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 10.3.x modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 10.0.x modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
- 10.1.x modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
1 call to PostForm::save()
- SocialAlbumPostForm::save in modules/
social_features/ social_album/ src/ Form/ SocialAlbumPostForm.php - Form submission handler for the 'save' action.
1 method overrides PostForm::save()
- SocialAlbumPostForm::save in modules/
social_features/ social_album/ src/ Form/ SocialAlbumPostForm.php - Form submission handler for the 'save' action.
File
- modules/
social_features/ social_post/ src/ Form/ PostForm.php, line 249
Class
- PostForm
- Form controller for Post edit forms.
Namespace
Drupal\social_post\FormCode
public function save(array $form, FormStateInterface $form_state) {
// Init form modes.
$this
->setFormMode();
$display = $this
->getFormDisplay($form_state);
if ($this->entity
->isNew()) {
if (isset($display) && ($display_id = $display
->get('id'))) {
if ($display_id === $this->postViewProfile) {
$account_profile = \Drupal::routeMatch()
->getParameter('user');
$this->entity
->get('field_recipient_user')
->setValue($account_profile);
}
elseif ($display_id === $this->postViewGroup) {
$group = \Drupal::routeMatch()
->getParameter('group');
$this->entity
->get('field_recipient_group')
->setValue($group);
}
}
}
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
$message = $this
->t('Your post %label has been posted.', [
'%label' => $this->entity
->label(),
]);
$this->moduleHandler
->alter('social_post_message', $message, $form_state);
$this
->messenger()
->addStatus($message);
break;
default:
$this
->messenger()
->addStatus($this
->t('Your post %label has been saved.', [
'%label' => $this->entity
->label(),
]));
}
}