You are here

function node_authlink_tokens in Node authorize link 8

Same name and namespace in other branches
  1. 7 node_authlink.module \node_authlink_tokens()

Implements hook_tokens().

File

./node_authlink.module, line 456
Node Authlink hooks and alters.

Code

function node_authlink_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  if ($type != 'node' || empty($data['node'])) {
    return;
  }
  $replacements = [];
  if ($type == 'node' && !empty($data['node']->authkey)) {
    $node = $data['node'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'authlink:authkey':
          $replacements[$original] = $node->authkey;
          break;
        case 'authlink:view-url':
          $replacements[$original] = node_authlink_get_url($node, 'view');
          break;
        case 'authlink:edit-url':
          $replacements[$original] = node_authlink_get_url($node, 'update');
          break;
        case 'authlink:delete-url':
          $replacements[$original] = node_authlink_get_url($node, 'delete');
          break;
      }
    }
  }
  return $replacements;
}