You are here

public function PostCommentController::getReplyForm in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  2. 8.2 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  3. 8.3 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  4. 8.4 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  5. 8.5 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  6. 8.6 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  7. 8.7 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  8. 8.8 modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  9. 10.3.x modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  10. 10.0.x modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  11. 10.1.x modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()
  12. 10.2.x modules/social_features/social_post/src/Controller/PostCommentController.php \Drupal\social_post\Controller\PostCommentController::getReplyForm()

Form constructor for the comment reply form.

There are several cases that have to be handled, including:

  • replies to comments
  • replies to entities

Parameters

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

\Drupal\Core\Entity\EntityInterface $entity: The entity this comment belongs to.

string $field_name: The field_name to which the comment belongs.

int $pid: (optional) Some comments are replies to other comments. In those cases, $pid is the parent comment's comment ID. Defaults to NULL.

Return value

array|\Symfony\Component\HttpFoundation\RedirectResponse An associative array containing:

  • An array for rendering the entity or parent comment.

    • comment_entity: If the comment is a reply to the entity.
    • comment_parent: If the comment is a reply to another comment.
  • comment_form: The comment form as a renderable array.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

Overrides CommentController::getReplyForm

File

modules/social_features/social_post/src/Controller/PostCommentController.php, line 17

Class

PostCommentController
Controller routine override to change relevant bits in the password reset.

Namespace

Drupal\social_post\Controller

Code

public function getReplyForm(Request $request, EntityInterface $entity, $field_name, $pid = NULL) {
  $account = $this
    ->currentUser();

  // The user is not just previewing a comment.
  if ($request->request
    ->get('op') != $this
    ->t('Preview')) {

    // $pid indicates that this is a reply to a comment.
    if ($pid) {

      // Load the parent comment.
      $comment = $this
        ->entityManager()
        ->getStorage('comment')
        ->load($pid);
    }
  }
  if ($entity
    ->getEntityTypeId() === 'post') {

    // Check if the post has been posted in a group.

    /* @var \Drupal\social_post\Entity\Post $entity */
    $group_id = $entity->field_recipient_group->target_id;
    if ($group_id) {

      /** @var \Drupal\group\Entity\Group $group */
      $group = entity_load('group', $group_id);
      if (!$group
        ->hasPermission('access posts in group', $account) || !$group
        ->hasPermission('add post entities in group', $account)) {
        if (!isset($comment)) {
          $comment = NULL;
        }

        /* @var \Drupal\Core\Url $url*/
        if ($url = $entity
          ->urlInfo('canonical')) {

          // Redirect the user to the correct entity.
          return $this
            ->redirectToOriginalEntity($url, $comment, $entity);
        }
      }
    }
  }
  return parent::getReplyForm($request, $entity, $field_name, $pid);
}