public function PostForm::save in Open Social 8
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.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()
- 10.2.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
File
- modules/
social_features/ social_post/ src/ Form/ PostForm.php, line 198
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:
drupal_set_message($this
->t('Your post %label has been posted.', [
'%label' => $this->entity
->label(),
]));
break;
default:
drupal_set_message($this
->t('Your post %label has been saved.', [
'%label' => $this->entity
->label(),
]));
}
}