You are here

class SocialPostAlbumAjaxCommentsController in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.0.x modules/social_features/social_post/modules/social_post_album/src/Controller/SocialPostAlbumAjaxCommentsController.php \Drupal\social_post_album\Controller\SocialPostAlbumAjaxCommentsController
  2. 10.1.x modules/social_features/social_post/modules/social_post_album/src/Controller/SocialPostAlbumAjaxCommentsController.php \Drupal\social_post_album\Controller\SocialPostAlbumAjaxCommentsController
  3. 10.2.x modules/social_features/social_post/modules/social_post_album/src/Controller/SocialPostAlbumAjaxCommentsController.php \Drupal\social_post_album\Controller\SocialPostAlbumAjaxCommentsController

Controller routines for AJAX comments routes.

Hierarchy

Expanded class hierarchy of SocialPostAlbumAjaxCommentsController

2 files declare their use of SocialPostAlbumAjaxCommentsController
RouteSubscriber.php in modules/social_features/social_post/modules/social_post_album/src/Routing/RouteSubscriber.php
social_post_album.module in modules/social_features/social_post/modules/social_post_album/social_post_album.module
The Social post album module.

File

modules/social_features/social_post/modules/social_post_album/src/Controller/SocialPostAlbumAjaxCommentsController.php, line 13

Namespace

Drupal\social_post_album\Controller
View source
class SocialPostAlbumAjaxCommentsController extends AjaxCommentsController {

  /**
   * The suffix for wrapper identifier of the comments section.
   */
  const WRAPPER_ID_SUFFIX = '-modal';

  /**
   * {@inheritdoc}
   */
  public function socialAdd(Request $request, EntityInterface $entity, $field_name, $pid = NULL) {
    $this->clearTempStore = FALSE;
    $response = parent::socialAdd($request, $entity, $field_name, $pid);
    if ($this->errors !== 0) {
      if ($this->errors !== NULL) {
        $this->tempStore
          ->deleteAll();
      }
      return $response;
    }
    $comment = $this
      ->entityTypeManager()
      ->getStorage('comment')
      ->create([
      'entity_id' => $entity
        ->id(),
      'pid' => $pid,
      'entity_type' => $entity
        ->getEntityTypeId(),
      'field_name' => $field_name,
    ]);
    $form = $this
      ->entityFormBuilder()
      ->getForm($comment);
    $this->tempStore
      ->setSelector('form_html_id', $form['#attributes']['id']);
    $field = $this
      ->renderCommentField($entity, $field_name);
    $field['#attributes']['id'] .= self::WRAPPER_ID_SUFFIX;
    $selectors = $this->tempStore
      ->getSelectors($request);
    $response
      ->addCommand(new ReplaceCommand($selectors['wrapper_html_id'] . self::WRAPPER_ID_SUFFIX, $field), TRUE);
    $this->tempStore
      ->deleteAll();
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxCommentsController::$clearTempStore protected property TRUE if temporary storage should be cleared.
AjaxCommentsController::$errors protected property The number of errors.
AjaxCommentsController::$pid protected property The parent comment's comment ID.
AjaxCommentsController::renderCommentField protected function
AjaxCommentsController::socialCancel public function Cancel handler for the cancel form.
SocialPostAlbumAjaxCommentsController::socialAdd public function Builds ajax response for adding a new comment without a parent comment. Overrides AjaxCommentsController::socialAdd
SocialPostAlbumAjaxCommentsController::WRAPPER_ID_SUFFIX constant The suffix for wrapper identifier of the comments section.