You are here

public function OrganizationTypeForm::save in CRM Core 8.3

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

Class

OrganizationTypeForm
Class OrganizationTypeForm.

Namespace

Drupal\crm_core_contact\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $primary_fields = [];
  foreach ($this->defaultPrimaryFields as $field) {
    $primary_fields[$field] = $form_state
      ->getValue($field);
  }
  $this->entity
    ->set('primary_fields', $primary_fields);
  $status = $this->entity
    ->save();
  if ($status == SAVED_UPDATED) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The organization type %name has been updated.', [
      '%name' => $this->entity
        ->label(),
    ]));
  }
  elseif ($status == SAVED_NEW) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The organization type %name has been added.', [
      '%name' => $this->entity
        ->label(),
    ]));
    $this
      ->logger('crm_core_individual')
      ->notice('Added organization type %name.', [
      '%name' => $this->entity
        ->label(),
    ]);
  }
  $form_state
    ->setRedirect('entity.crm_core_organization_type.collection');
}