You are here

public function PostForm::save in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  2. 8.2 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  3. 8.3 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  4. 8.4 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  5. 8.5 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  6. 8.6 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  7. 8.7 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  8. 8.8 modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  9. 10.3.x modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  10. 10.0.x modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  11. 10.1.x modules/social_features/social_post/src/Form/PostForm.php \Drupal\social_post\Form\PostForm::save()
  12. 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\Form

Code

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(),
      ]));
  }
}