You are here

public function OrganizationForm::save in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_contact/src/Form/OrganizationForm.php \Drupal\crm_core_contact\Form\OrganizationForm::save()
  2. 8.2 modules/crm_core_contact/src/Form/OrganizationForm.php \Drupal\crm_core_contact\Form\OrganizationForm::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_contact/src/Form/OrganizationForm.php, line 20

Class

OrganizationForm
Class OrganizationForm.

Namespace

Drupal\crm_core_contact\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $organization = $this->entity;
  $status = $organization
    ->save();
  if ($status == SAVED_UPDATED) {
    drupal_set_message($this
      ->t('The organization %name has been updated.', [
      '%name' => $organization
        ->label(),
    ]));
    if ($organization
      ->access('view')) {
      $form_state
        ->setRedirect('entity.crm_core_organization.canonical', [
        'crm_core_organization' => $organization
          ->id(),
      ]);
    }
    else {
      $form_state
        ->setRedirect('entity.crm_core_organization.collection');
    }
  }
  elseif ($status == SAVED_NEW) {
    drupal_set_message($this
      ->t('The organization %name has been added.', [
      '%name' => $organization
        ->label(),
    ]));
    \Drupal::logger('crm_core_organization')
      ->notice('Added organization %name.', [
      '%name' => $organization
        ->label(),
    ]);
    $form_state
      ->setRedirect('entity.crm_core_organization.collection');
  }
}