You are here

private function ActionLinkNoJsController::generateResponse in Flag Lists 4.0.x

Same name and namespace in other branches
  1. 8 src/Controller/ActionLinkNoJsController.php \Drupal\flag_lists\Controller\ActionLinkNoJsController::generateResponse()

Generates a response after the flag has been updated.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

string $message: The message to display.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse The response object.

2 calls to ActionLinkNoJsController::generateResponse()
ActionLinkNoJsController::flag in src/Controller/ActionLinkNoJsController.php
Performs a flagging when called via a route.
ActionLinkNoJsController::unflag in src/Controller/ActionLinkNoJsController.php
Performs a unflagging when called via a route.

File

src/Controller/ActionLinkNoJsController.php, line 155

Class

ActionLinkNoJsController
Returns nojs responses to flag and unflag action links.

Namespace

Drupal\flag_lists\Controller

Code

private function generateResponse(EntityInterface $entity, $message) {
  $this->messenger
    ->addMessage($message);
  if ($entity
    ->hasLinkTemplate('canonical')) {

    // Redirect back to the entity. A passed in destination query parameter
    // will automatically override this.
    $url_info = $entity
      ->toUrl();
    $options['absolute'] = TRUE;
    $url = Url::fromRoute($url_info
      ->getRouteName(), $url_info
      ->getRouteParameters(), $options);
    $response = new RedirectResponse($url
      ->toString());
  }
  else {

    // For entities that don't have a canonical URL (like paragraphs),
    // redirect to the front page.
    $front = Url::fromUri('internal:/');
    $response = new RedirectResponse($front);
  }
  return $response;
}