Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
N
node_authlink
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
node_authlink
Commits
0fa6a478
Commit
0fa6a478
authored
Aug 22, 2018
by
akalam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored removed functions from d8 api
parent
9213ee7a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
node_authlink.module
node_authlink.module
+15
-9
No files found.
node_authlink.module
View file @
0fa6a478
<?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_b
ytes
(
64
));
$node
->
authkey
=
hash
(
'sha256'
,
Crypt
::
randomB
ytes
(
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_b
ytes
(
64
));
$authkey
=
isset
(
$node
->
authkey
)
?
$node
->
authkey
:
hash
(
'sha256'
,
Crypt
::
randomB
ytes
(
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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment