You are here

public function ActivityForm::save in CRM Core 8.2

Same name and namespace in other branches
  1. 8.3 modules/crm_core_activity/src/Form/ActivityForm.php \Drupal\crm_core_activity\Form\ActivityForm::save()
  2. 8 modules/crm_core_activity/src/Form/ActivityForm.php \Drupal\crm_core_activity\Form\ActivityForm::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/crm_core_activity/src/Form/ActivityForm.php, line 16

Class

ActivityForm
Class ActivityForm.

Namespace

Drupal\crm_core_activity\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $activity = $this->entity;
  $status = $activity
    ->save();
  $t_args = [
    '%title' => $activity
      ->label(),
    'link' => $activity
      ->url(),
  ];
  if ($status == SAVED_UPDATED) {
    drupal_set_message($this
      ->t('Activity %title edited.', $t_args));
    if ($activity
      ->access('view')) {
      $form_state
        ->setRedirect('entity.crm_core_activity.canonical', [
        'crm_core_activity' => $activity
          ->id(),
      ]);
    }
    else {
      $form_state
        ->setRedirect('entity.crm_core_contact.collection');
    }
  }
  elseif ($status == SAVED_NEW) {
    drupal_set_message($this
      ->t('Activity %title created.', $t_args));
    \Drupal::logger('crm_core_contact')
      ->notice('Activity %title created.', $t_args);
    $form_state
      ->setRedirect('entity.crm_core_contact.collection');
  }
  if ($activity
    ->access('view')) {
    $form_state
      ->setRedirect('entity.crm_core_activity.canonical', [
      'crm_core_activity' => $activity
        ->id(),
    ]);
  }
  else {
    $form_state
      ->setRedirect('entity.crm_core_activity.collection');
  }
}