You are here

public function ProfileFormController::save in Profile 2 8

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

src/ProfileFormController.php, line 116
Contains \Drupal\profile\ProfileFormController.

Class

ProfileFormController
Form controller for profile forms.

Namespace

Drupal\profile

Code

public function save(array $form, FormStateInterface $form_state) {
  $profile_type = ProfileType::load($this->entity
    ->bundle());

  // Active profile for non administers if profile is new.
  if (!\Drupal::currentUser()
    ->hasPermission('administer profiles') && $this->entity
    ->isNew()) {
    $this->entity
      ->setActive(TRUE);
  }
  switch ($this->entity
    ->save()) {
    case SAVED_NEW:
      drupal_set_message(t('%label profile has been created.', array(
        '%label' => $profile_type
          ->label(),
      )));
      break;
    case SAVED_UPDATED:
      drupal_set_message(t('%label profile has been updated.', array(
        '%label' => $profile_type
          ->label(),
      )));
      break;
  }
  $form_state
    ->setRedirect('entity.user.canonical', array(
    'user' => $this->entity
      ->getOwnerId(),
  ));
}