You are here

function node_authlink_get_url in Node authorize link 8

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

Get edit URL of specified node.

Parameters

$node Node object or NID.:

string $op Operation to do with node. view, update (default) or delete.:

null $revision_id:

Return value

bool|\Drupal\Core\GeneratedUrl|string

2 calls to node_authlink_get_url()
NodeAuthlinkNodeForm::buildForm in src/Form/NodeAuthlinkNodeForm.php
Form constructor.
node_authlink_tokens in ./node_authlink.module
Implements hook_tokens().

File

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

Code

function node_authlink_get_url($node, $op = 'view', $revision_id = NULL) {
  if (is_numeric($node)) {
    $node = Node::load($node);
  }
  if (!isset($node->authkey)) {
    return FALSE;
  }
  switch ($op) {
    case 'view':
      if (is_numeric($revision_id)) {
        $route_name = 'entity.node.revision';
      }
      else {
        $route_name = 'entity.node.canonical';
      }
      break;
    case 'update':
      $route_name = 'entity.node.edit_form';
      break;
    case 'delete':
      $route_name = 'entity.node.delete_form';
      break;
    default:
      return FALSE;
  }
  $arguments = [
    'node' => $node
      ->id(),
  ];
  if (is_numeric($revision_id)) {
    $arguments['node_revision'] = $revision_id;
  }
  $url = Url::fromRoute($route_name, $arguments, [
    'absolute' => TRUE,
    'query' => [
      'authkey' => $node->authkey,
    ],
  ]);
  return $url
    ->toString();
}