You are here

private function ActionLinkController::generateResponse in Flag 8.4

Generates a response after the flag has been updated.

Parameters

\Drupal\flag\FlagInterface $flag: The flag entity.

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

string $message: (optional) The message to flash.

Return value

\Drupal\Core\Ajax\AjaxResponse The response object.

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

File

src/Controller/ActionLinkController.php, line 129

Class

ActionLinkController
Controller responses to flag and unflag action links.

Namespace

Drupal\flag\Controller

Code

private function generateResponse(FlagInterface $flag, EntityInterface $entity, $message) {

  // Create a new AJAX response.
  $response = new AjaxResponse();

  // Get the link type plugin.
  $link_type = $flag
    ->getLinkTypePlugin();

  // Generate the link render array.
  $link = $link_type
    ->getAsFlagLink($flag, $entity);

  // Generate a CSS selector to use in a JQuery Replace command.
  $selector = '.js-flag-' . Html::cleanCssIdentifier($flag
    ->id()) . '-' . $entity
    ->id();

  // Create a new JQuery Replace command to update the link display.
  $replace = new ReplaceCommand($selector, $this->renderer
    ->renderPlain($link));
  $response
    ->addCommand($replace);

  // Push a message pulsing command onto the stack.
  $pulse = new ActionLinkFlashCommand($selector, $message);
  $response
    ->addCommand($pulse);
  return $response;
}