You are here

public function UnpublishedNodesRedirectUtils::checksBeforeRedirect in Unpublished Nodes Redirect 8

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

Checks that a node meets the criteria for a redirect.

Parameters

int $node_status: Status of node 0 is unpulished and 1 is published.

bool $is_anonymous: 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()
UnpublishedNodesRedirectSubscriber::redirectUnpublishedNodes in src/EventSubscriber/UnpublishedNodesRedirectSubscriber.php
Fires redirects whenever the KernelEvents::RESPONSE event is dispatched.

File

src/Utils/UnpublishedNodesRedirectUtils.php, line 66

Class

UnpublishedNodesRedirectUtils
Utility class for Unpublished nodes redirect module.

Namespace

Drupal\unpublished_nodes_redirect\Utils

Code

public function checksBeforeRedirect($node_status, $is_anonymous, $redirect_path, $response_code) {

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