/**
  * Form submit callback for save as completed submit action.
  *
  * Change items to needs review state and task to completed status.
  */
 public function saveAsComplete(array &$form, FormStateInterface $form_state)
 {
     /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
     $task = $this->entity->getTask();
     /** @var LocalTaskItem $task_item */
     $task_item = $this->entity;
     $task_item->completed();
     $task_item->save();
     // Mark the task as completed if all assigned job items are at needs done.
     $all_done = TRUE;
     /** @var \Drupal\tmgmt_local\Entity\LocalTaskItem $item */
     foreach ($task->getItems() as $item) {
         if (!$item->isCompleted() && !$item->isClosed()) {
             $all_done = FALSE;
             break;
         }
     }
     if ($all_done) {
         $task->setStatus(LocalTaskInterface::STATUS_COMPLETED);
         // If the task is now completed, redirect back to the overview.
         $view = Views::getView('tmgmt_local_task_overview');
         $view->initDisplay();
         $form_state->setRedirect($view->getUrl()->getRouteName());
     } else {
         // If there are more task items, redirect back to the task.
         $uri = $task->urlInfo();
         $form_state->setRedirect($uri->getRouteName(), $uri->getRouteParameters());
     }
     /** @var \Drupal\tmgmt\Entity\JobItem $job_item */
     $job_item = $this->entity->getJobItem();
     // Add the translations to the job item.
     $job_item->addTranslatedData($this->prepareData($task_item->getData()), [], TMGMT_DATA_ITEM_STATE_TRANSLATED);
     drupal_set_message(t('The translation for <a href=:task_item>@task_item_title</a> has been saved as completed.', [':task_item' => $task_item->urlInfo()->toString(), '@task_item_title' => $task_item->label()]));
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function addTaskItem(JobItemInterface $job_item)
 {
     // Save the task to get an id.
     if ($this->isNew()) {
         $this->save();
     }
     $local_task = LocalTaskItem::create(array('tltid' => $this->id(), 'tjiid' => $job_item->id()));
     $local_task->save();
     return $local_task;
 }