You are here

protected function VoteController::prepareResponse in Rate 8

Prepare a response object.

Parameters

string $entity_type_id: The entity type.

int $entity_id: The entity id.

string $bundle: The bundle name.

string $widget_type: Widget type.

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

Return value

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

2 calls to VoteController::prepareResponse()
VoteController::undoVote in src/Controller/VoteController.php
Undo a vote.
VoteController::vote in src/Controller/VoteController.php
Record a vote.

File

src/Controller/VoteController.php, line 145

Class

VoteController
Returns responses for Rate routes.

Namespace

Drupal\rate\Controller

Code

protected function prepareResponse($entity_type_id, $entity_id, $bundle, $widget_type, Request $request) {
  $use_ajax = $this->config
    ->get('use_ajax');

  // If Request was AJAX and voting on a node, send AJAX response.
  if ($use_ajax) {
    $response = new AjaxResponse();
    $vote_widget = $this->voteWidget
      ->buildRateVotingWidget($entity_id, $entity_type_id, $bundle, $widget_type);
    $widget_id = '[data-drupal-selector=rate-' . $entity_type_id . '-' . $entity_id . ']';
    $html = $this->renderer
      ->render($vote_widget);
    $response
      ->addCommand(new ReplaceCommand($widget_id, $html));
    return $response;
  }
  else {
    $url = $request
      ->getUriForPath($request
      ->getPathInfo());
    return new RedirectResponse($url);
  }
}