You are here

public function AjaxCommentsController::socialCancel in Open Social 8.9

Same name and namespace in other branches
  1. 8.8 modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  2. 10.3.x modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  3. 10.0.x modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  4. 10.1.x modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  5. 10.2.x modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()

Cancel handler for the cancel 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::socialCancel'
social_ajax_comments.routing.yml in modules/custom/social_ajax_comments/social_ajax_comments.routing.yml
modules/custom/social_ajax_comments/social_ajax_comments.routing.yml

File

modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php, line 28

Class

AjaxCommentsController
Controller routines for AJAX comments routes.

Namespace

Drupal\social_ajax_comments\Controller

Code

public function socialCancel(Request $request, $cid) {

  // This is based on AjaxCommentsController::cancel.
  // the only change is we have some more wrappers we need to remove,
  // we can't tell this to ajax_comments because we render it in our template
  // so instead we will just remove whatever we need.
  $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',
    ]));
  }

  // Replace the # from the form_html_id selector and add .social_ so we know
  // that we are sure we are just removing our specific form class.
  $social_form_id = str_replace('#', '.social_reply_form_wrapper_', $form_html_id);

  // Remove the form, based on $variables['comment_wrapper'] in form.inc.
  $response
    ->addCommand(new RemoveCommand($social_form_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;
}