You are here

public function AjaxCommentsController::delete in AJAX Comments 8

Builds ajax response for deleting a comment.

Parameters

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

\Drupal\comment\CommentInterface $comment: The comment entity.

Return value

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

1 string reference to 'AjaxCommentsController::delete'
ajax_comments.routing.yml in ./ajax_comments.routing.yml
ajax_comments.routing.yml

File

src/Controller/AjaxCommentsController.php, line 526

Class

AjaxCommentsController
Controller routines for AJAX comments routes.

Namespace

Drupal\ajax_comments\Controller

Code

public function delete(Request $request, CommentInterface $comment) {
  $response = new AjaxResponse();

  // Store the selectors from the incoming request, if applicable.
  // If the selectors are not in the request, the stored ones will
  // not be overwritten.
  $this->tempStore
    ->getSelectors($request, $overwrite = TRUE);
  $response
    ->addCommand(new CloseModalDialogCommand());

  // Rebuild the form to trigger form submission.
  $this
    ->entityFormBuilder()
    ->getForm($comment, 'delete');

  // Build the updated comment field and insert into a replaceWith response.
  // Also prepend any status messages in the response.
  $response = $this
    ->buildCommentFieldResponse($request, $response, $comment
    ->getCommentedEntity(), $comment
    ->get('field_name')->value);

  // Calling $this->buildCommentFieldResponse() updates the stored selectors.
  $selectors = $this->tempStore
    ->getSelectors($request);
  $wrapper_html_id = $selectors['wrapper_html_id'];
  $response = $this
    ->addMessages($request, $response, $wrapper_html_id);

  // Clear out the tempStore variables.
  $this->tempStore
    ->deleteAll();
  return $response;
}