You are here

public static function UnpublishedNodesRedirectUtils::checksBeforeRedirect in Unpublished Nodes Redirect 2.x

Same name and namespace in other branches
  1. 8 src/Utils/UnpublishedNodesRedirectUtils.php \Drupal\unpublished_nodes_redirect\Utils\UnpublishedNodesRedirectUtils::checksBeforeRedirect()

Checks that a node meets the criteria for a redirect.

Parameters

bool $node_status: Published or Unpublished.

bool $is_published: A boolean indicating if a user is anonymous.

string $redirect_path: Path to be used for redirect.

string $response_code: HTTP response code e.g 301.

Return value

bool

1 call to UnpublishedNodesRedirectUtils::checksBeforeRedirect()
UnpublishedNodesRedirectOn403Subscriber::on403 in src/EventSubscriber/UnpublishedNodesRedirectOn403Subscriber.php
Fires redirects whenever a 403 meets the criteria for unpublished nodes.

File

src/Utils/UnpublishedNodesRedirectUtils.php, line 66

Class

UnpublishedNodesRedirectUtils
Utility class for Unpublished nodes redirect module.

Namespace

Drupal\unpublished_nodes_redirect\Utils

Code

public static function checksBeforeRedirect($is_published, $is_anonymous, $redirect_path, $response_code) {

  // Node is unpublished, user is not logged in and there is a redirect path
  // and response code.
  if (!$is_published && $is_anonymous && !empty($redirect_path) && !empty($response_code) && $response_code != 0) {
    return TRUE;
  }
  return FALSE;
}