You are here

public function LocalTaskController::assignToMe in Translation Management Tool 8

Assign this task to the current user and reloads the listing page.

Parameters

\Drupal\tmgmt_local\LocalTaskInterface $tmgmt_local_task: The task being acted upon.

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

\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.

1 string reference to 'LocalTaskController::assignToMe'
tmgmt_local.routing.yml in translators/tmgmt_local/tmgmt_local.routing.yml
translators/tmgmt_local/tmgmt_local.routing.yml

File

translators/tmgmt_local/src/Controller/LocalTaskController.php, line 29

Class

LocalTaskController
Returns responses for Local task routes.

Namespace

Drupal\tmgmt_local\Controller

Code

public function assignToMe(LocalTaskInterface $tmgmt_local_task, Request $request) {
  $tmgmt_local_task
    ->assign(\Drupal::currentUser());
  $tmgmt_local_task
    ->save();
  $this
    ->messenger()
    ->addStatus(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>');
}