You are here

public function AjaxCommentsController::cancel in AJAX Comments 8

Cancel handler for the comment edit form.

Parameters

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

int $cid: The id of the comment being edited, or 0 if this is a new comment.

Return value

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

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

File

src/Controller/AjaxCommentsController.php, line 487

Class

AjaxCommentsController
Controller routines for AJAX comments routes.

Namespace

Drupal\ajax_comments\Controller

Code

public function cancel(Request $request, $cid) {
  $response = new AjaxResponse();

  // Get the selectors.
  $selectors = $this->tempStore
    ->getSelectors($request, $overwrite = TRUE);
  $wrapper_html_id = $selectors['wrapper_html_id'];
  $form_html_id = $selectors['form_html_id'];
  if ($cid != 0) {

    // Show the hidden anchor.
    $response
      ->addCommand(new InvokeCommand('a#comment-' . $cid, 'show', [
      200,
      'linear',
    ]));

    // Show the hidden comment.
    $response
      ->addCommand(new InvokeCommand(static::getCommentSelectorPrefix() . $cid, 'show', [
      200,
      'linear',
    ]));
  }

  // Remove the form.
  $response
    ->addCommand(new RemoveCommand($form_html_id));

  // Remove any messages, if applicable.
  $response
    ->addCommand(new RemoveCommand($wrapper_html_id . ' .js-ajax-comments-messages'));

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