Skip to content
Snippets Groups Projects

Assign the authkey after generated on create

1 file
+ 5
0
Compare changes
  • Side-by-side
  • Inline
+ 5
0
@@ -390,6 +390,8 @@ function node_authlink_create($node) {
@@ -390,6 +390,8 @@ function node_authlink_create($node) {
// Allow key generate without load node object.
// Allow key generate without load node object.
if (is_numeric($node)) {
if (is_numeric($node)) {
$nid = $node;
$nid = $node;
 
/** @var \Drupal\node\NodeInterface $node */
 
$node = Node::load($nid);
}
}
else {
else {
$nid = $node->id();
$nid = $node->id();
@@ -404,6 +406,9 @@ function node_authlink_create($node) {
@@ -404,6 +406,9 @@ function node_authlink_create($node) {
// Generate key if not yet.
// Generate key if not yet.
$authkey = $node->authkey ?? hash('sha256', random_bytes(64));
$authkey = $node->authkey ?? hash('sha256', random_bytes(64));
 
// Set it back on the node object.
 
$node->authkey = $authkey;
 
// Save to DB.
// Save to DB.
\Drupal::database()->insert('node_authlink_nodes')
\Drupal::database()->insert('node_authlink_nodes')
->fields([
->fields([
Loading