コード例 #1
0
 /**
  * Assign this task to the current user and reloads the listing page.
  *
  * @param \Drupal\tmgmt_local\LocalTaskInterface $tmgmt_local_task
  *   The task being acted upon.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse
  *   Either returns a rebuilt listing page as an AJAX response, or redirects
  *   back to the listing page.
  */
 public function assignToMe(LocalTaskInterface $tmgmt_local_task, Request $request)
 {
     $tmgmt_local_task->assign(\Drupal::currentUser());
     $tmgmt_local_task->save();
     drupal_set_message(t('The task has been assigned to you.'));
     // If the request is via AJAX, return the rendered list as JSON.
     if ($request->request->get('js')) {
         $list = $this->entityTypeManager()->getListBuilder('view')->render();
         $response = new AjaxResponse();
         $response->addCommand(new ReplaceCommand('#views-entity-list', $list));
         return $response;
     }
     // Otherwise, redirect back to the page.
     return $this->redirect('<current>');
 }
コード例 #2
0
ファイル: LocalTaskForm.php プロジェクト: andrewl/andrewlnet
 /**
  * {@inheritdoc}
  */
 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);
         drupal_set_message(t('Assigned to user @assignee_name.', ['@assignee_name' => $assignee->getAccountName()]));
     } else {
         $task->setStatus(LocalTaskInterface::STATUS_UNASSIGNED);
         drupal_set_message(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());
 }