function node_authlink_check_authlink in Node authorize link 8
Check if a node has access to a node via authlink and grant it the query parameter is correct.
Parameters
\Drupal\node\NodeInterface $node:
$op:
\Drupal\Core\Session\AccountInterface $account:
Return value
bool
3 calls to node_authlink_check_authlink()
- NodeAuthlinkGroupContentAccessControlHandler::entityAccess in src/
Access/ NodeAuthlinkGroupContentAccessControlHandler.php - Checks access to an operation on the entity.
- NodeRevisionAccessCheck::checkAccess in src/
Access/ NodeRevisionAccessCheck.php - Checks node revision access.
- node_authlink_node_access in ./
node_authlink.module - Implements hook_node_access().
File
- ./
node_authlink.module, line 303 - Node Authlink hooks and alters.
Code
function node_authlink_check_authlink(NodeInterface $node, $op, AccountInterface $account) {
$config = \Drupal::config('node_authlink.settings');
// Check key if:
if (isset($_GET['authkey']) && isset($node->authkey)) {
// authkey in node is setand
if ($node->authkey == $_GET['authkey']) {
// Start session
if ($account
->isAnonymous() && !isset($_SESSION['node_authlink_nodes'])) {
/** @var \Drupal\Core\Session\SessionManager $session_manager */
$session_manager = \Drupal::service('session_manager');
$session_manager
->start();
}
// Save allowed grants to session
$config_grants = $config
->get('grants');
$_SESSION['node_authlink_nodes'][$node
->id()] = $config_grants[$node
->bundle()];
}
}
// Permit if checked
if (isset($_SESSION['node_authlink_nodes'][$node
->id()]) && in_array($op, $_SESSION['node_authlink_nodes'][$node
->id()], TRUE)) {
return TRUE;
}
return FALSE;
}