You are here

public function AjaxCommentsController::socialCancel in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  2. 8.8 modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  3. 10.3.x modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  4. 10.0.x modules/custom/social_ajax_comments/src/Controller/AjaxCommentsController.php \Drupal\social_ajax_comments\Controller\AjaxCommentsController::socialCancel()
  5. 10.1.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 49

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, TRUE);
  $wrapper_html_id = $selectors['wrapper_html_id'];
  $form_html_id = $selectors['form_html_id'];
  if ($cid != 0) {
    $prefixes = [
      // Show the hidden anchor.
      'a#comment-',
      // Show the hidden comment.
      static::getCommentSelectorPrefix(),
    ];
    foreach ($prefixes as $prefix) {
      $command = new InvokeCommand($prefix . $cid, 'show', [
        200,
        'linear',
      ]);
      $response
        ->addCommand($command);
    }
  }

  // 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;
}