Commit 0fa6a478 authored by akalam's avatar akalam

refactored removed functions from d8 api

parent 9213ee7a
<?php
// $Id$
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -45,7 +46,9 @@ function node_authlink_form_node_type_form_alter(&$form, FormStateInterface &$fo
];
// Time periods: none, 1 day, 1 week, 4 weeks
$period = drupal_map_assoc([0, 86400, 604800, 2419200], 'format_interval');
$time_periods = [0, 86400, 604800, 2419200];
$period = array_map('format_interval', array_combine($time_periods, $time_periods));
$period[0] = '<' . t('disabled') . '>';
$form['node_authlink']['node_authlink_expire'] = [
'#type' => 'select',
......@@ -241,14 +244,15 @@ function node_authlink_node_access(NodeInterface $node, $op, AccountInterface $a
*
* Pre-generate auth key for the new node (e.g. for use in Rules).
*/
function node_authlink_node_presave($node) {
function node_authlink_node_presave(Node $node) {
// Ignore if node type is disabled
if (!variable_get('node_authlink_enable_' . $node->type, FALSE)) {
$config = \Drupal::config('node_authlink.settings');
if (!$config->get('enable.' . $node->bundle())) {
return;
}
// Generate key
$node->authkey = hash('sha256', drupal_random_bytes(64));
$node->authkey = hash('sha256', Crypt::randomBytes(64));
}
/**
......@@ -262,16 +266,17 @@ function node_authlink_node_insert($node) {
$nid = $node;
}
else {
$nid = $node->nid;
$nid = $node->id();
$config = \Drupal::config('node_authlink.settings');
// Ignore if node type is disabled
if (!variable_get('node_authlink_enable_' . $node->type, FALSE)) {
if (!$config->get('enable.' . $node->bundle())) {
return;
}
}
// Generate key if not yet
$authkey = isset($node->authkey) ? $node->authkey : hash('sha256', drupal_random_bytes(64));
$authkey = isset($node->authkey) ? $node->authkey : hash('sha256', Crypt::randomBytes(64));
// Save to DB
db_insert('node_authlink_nodes')
......@@ -288,9 +293,10 @@ function node_authlink_node_insert($node) {
*/
function node_authlink_cron() {
$node_types = node_type_get_types();
$config = \Drupal::config('node_authlink.settings');
foreach ($node_types as $type) {
$expire = variable_get('node_authlink_expire_' . $type->type, 0);
$expire = $config->get('expire.' . $type->id());
if (!$expire) {
continue;
}
......@@ -299,7 +305,7 @@ function node_authlink_cron() {
$query = db_select('node', 'n');
$query->leftJoin('node_authlink_nodes', 'a', 'n.nid = a.nid');
$query->fields('n', ['nid'])
->condition('n.type', $type->type)
->condition('n.type', $type->id())
->condition('a.created', time() - $expire, '<');
$nids = $query->execute()->fetchCol();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment