You are here

function social_post_album_comment_redirect 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/social_post_album.module \social_post_album_comment_redirect()
  2. 10.1.x modules/social_features/social_post/modules/social_post_album/social_post_album.module \social_post_album_comment_redirect()
  3. 10.2.x modules/social_features/social_post/modules/social_post_album/social_post_album.module \social_post_album_comment_redirect()

Submit callback for the user comment form to redirect without ajax module.

1 string reference to 'social_post_album_comment_redirect'
social_post_album_form_comment_form_alter in modules/social_features/social_post/modules/social_post_album/social_post_album.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_post/modules/social_post_album/social_post_album.module, line 196
The Social post album module.

Code

function social_post_album_comment_redirect($form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
  $module_handler = \Drupal::service('module_handler');
  if (!$module_handler
    ->moduleExists('social_ajax_comments') || !$module_handler
    ->moduleExists('ajax_comments')) {
    $redirect_after_save = \Drupal::request()->request
      ->get('redirect_after_save');
    if (strpos($redirect_after_save, '/open/images/') !== FALSE) {

      /** @var \Drupal\comment\CommentInterface $comment */
      $comment = $form_state
        ->getFormObject()
        ->getEntity();

      /** @var \Drupal\social_post\Entity\PostInterface $post */
      $post = $comment
        ->getCommentedEntity();
      $form_state
        ->setRedirect('entity.post.canonical', [
        'post' => $post
          ->id(),
      ], [
        'fragment' => 'comment-' . $comment
          ->id(),
      ]);
    }
  }
}