You are here

public function LocalTaskForm::save in Translation Management Tool 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

translators/tmgmt_local/src/Form/LocalTaskForm.php, line 150

Class

LocalTaskForm
Form controller for the localTask edit forms.

Namespace

Drupal\tmgmt_local\Form

Code

public function save(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
  $task = $this
    ->getEntity();
  if (!empty($form_state
    ->getValue('tuid'))) {

    /** @var User $assignee */
    $assignee = User::load($form_state
      ->getValue('tuid'));
    $task
      ->assign($assignee);
    $this
      ->messenger()
      ->addStatus(t('Assigned to user @assignee_name.', [
      '@assignee_name' => $assignee
        ->getAccountName(),
    ]));
  }
  else {
    $task
      ->setStatus(LocalTaskInterface::STATUS_UNASSIGNED);
    $this
      ->messenger()
      ->addStatus(t('Unassigned from translation local task @label.', array(
      '@label' => $task
        ->label(),
    )));
  }
  $this->entity
    ->save();
  $view = Views::getView('tmgmt_local_task_overview');
  $view
    ->initDisplay();
  $form_state
    ->setRedirect($view
    ->getUrl()
    ->getRouteName());
}