public function LocalTaskForm::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());
}