You are here

public function RelationForm::save in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_user_sync/src/Form/RelationForm.php \Drupal\crm_core_user_sync\Form\RelationForm::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_user_sync/src/Form/RelationForm.php, line 42

Class

RelationForm
Form controller for the relation entity edit forms.

Namespace

Drupal\crm_core_user_sync\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $entity = $this
    ->getEntity();
  $result = $entity
    ->save();
  $link = $entity
    ->toLink($this
    ->t('View'))
    ->toString();
  $logger_arguments = [
    'link' => $link,
  ];
  if ($result == SAVED_NEW) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('New relation has been created.'));
    $this
      ->logger('crm_core_user_sync')
      ->notice('Created new relation', $logger_arguments);
  }
  else {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The relation has been updated.'));
    $this
      ->logger('crm_core_user_sync')
      ->notice('Relation updated', $logger_arguments);
  }
  $form_state
    ->setRedirect('entity.crm_core_user_sync_relation.collection');
}