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
e29e7a69
Commit
e29e7a69
authored
Oct 22, 2018
by
akalam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SP-832199932200423
: Added User interface for viewing authlinks for revisions.
parent
69a055a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
11 deletions
+90
-11
node_authlink.module
node_authlink.module
+16
-4
src/Form/NodeAuthlinkNodeForm.php
src/Form/NodeAuthlinkNodeForm.php
+74
-7
No files found.
node_authlink.module
View file @
e29e7a69
...
...
@@ -200,9 +200,12 @@ function node_authlink_load_authkey($nid) {
* Get edit URL of specified node.
*
* @param $node Node object or NID.
* @param $op Operation to do with node. view, edit (default) or delete.
* @param string $op Operation to do with node. view, edit (default) or delete.
* @param null $revision_id
*
* @return bool|\Drupal\Core\GeneratedUrl|string
*/
function
node_authlink_get_url
(
$node
,
$op
=
'view'
)
{
function
node_authlink_get_url
(
$node
,
$op
=
'view'
,
$revision_id
=
NULL
)
{
if
(
is_numeric
(
$node
))
{
$node
=
Node
::
load
(
$node
);
}
...
...
@@ -213,7 +216,12 @@ function node_authlink_get_url($node, $op = 'view') {
switch
(
$op
)
{
case
'view'
:
$route_name
=
'entity.node.canonical'
;
if
(
is_numeric
(
$revision_id
))
{
$route_name
=
'entity.node.revision'
;
}
else
{
$route_name
=
'entity.node.canonical'
;
}
break
;
case
'edit'
:
$route_name
=
'entity.node.edit_form'
;
...
...
@@ -225,8 +233,12 @@ function node_authlink_get_url($node, $op = 'view') {
return
FALSE
;
}
$arguments
=
[
'node'
=>
$node
->
id
()];
if
(
is_numeric
(
$revision_id
))
{
$arguments
[
'node_revision'
]
=
$revision_id
;
}
$url
=
Url
::
fromRoute
(
$route_name
,
[
'node'
=>
$node
->
id
()]
,
[
$url
=
Url
::
fromRoute
(
$route_name
,
$arguments
,
[
'absolute'
=>
TRUE
,
'query'
=>
[
'authkey'
=>
$node
->
authkey
],
]);
...
...
src/Form/NodeAuthlinkNodeForm.php
View file @
e29e7a69
...
...
@@ -69,15 +69,82 @@ class NodeAuthlinkNodeForm extends FormBase {
if
(
!
$op
)
{
continue
;
}
$url
=
node_authlink_get_url
(
$node
,
$op
);
if
(
$url
)
{
// @todo: use a table instead.
$form
[
'link_'
.
$op
]
=
[
'#type'
=>
'markup'
,
'#markup'
=>
"<p><strong>
$op
</strong>:
$url
</p>"
,
];
// If $op is view, load all revisions.
$has_revisions
=
FALSE
;
if
(
$op
==
'view'
)
{
$has_revisions
=
TRUE
;
$node_storage
=
\
Drupal
::
entityManager
()
->
getStorage
(
'node'
);
$result
=
$node_storage
->
getQuery
()
->
allRevisions
()
->
condition
(
$node
->
getEntityType
()
->
getKey
(
'id'
),
$node
->
id
())
->
sort
(
$node
->
getEntityType
()
->
getKey
(
'revision'
),
'DESC'
)
->
range
(
0
,
50
)
->
execute
();
if
(
!
empty
(
$result
))
{
$revision_options
=
[];
foreach
(
$result
as
$vid
=>
$nid
)
{
$revision
=
$node_storage
->
loadRevision
(
$vid
);
$langcode
=
$node
->
language
()
->
getId
();
// Only show revisions that are affected by the language that is being
// displayed.
if
(
$revision
->
hasTranslation
(
$langcode
)
&&
$revision
->
getTranslation
(
$langcode
)
->
isRevisionTranslationAffected
())
{
// Use revision link to link to revisions that are not active.
$dateFormatter
=
\
Drupal
::
service
(
'date.formatter'
);
$date
=
$dateFormatter
->
format
(
$revision
->
revision_timestamp
->
value
,
'short'
);
if
(
$revision
->
isDefaultRevision
())
{
$revision_options
[
$vid
]
=
[
'text'
=>
$this
->
t
(
'Current revision'
),
'url'
=>
node_authlink_get_url
(
$node
,
$op
),
];
}
else
{
$revision_options
[
$vid
]
=
[
'text'
=>
$date
,
'url'
=>
node_authlink_get_url
(
$node
,
$op
,
$vid
),
];
}
}
}
}
}
if
(
$has_revisions
)
{
$form
[
'revisions'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Revisions'
),
'#options'
=>
[],
];
// @todo: use a table instead.
foreach
(
$revision_options
as
$vid
=>
$revision_option
)
{
$form
[
'revisions'
][
'#options'
][
$vid
]
=
$revision_option
[
'text'
];
$form
[
'link_'
.
$op
.
'_'
.
$vid
]
=
[
'#type'
=>
'item'
,
'#markup'
=>
"<p><strong>"
.
$op
.
"</strong>: "
.
$revision_option
[
'url'
]
.
"</p>"
,
'#states'
=>
[
'visible'
=>
[
'[name="revisions"]'
=>
[
'value'
=>
$vid
],
],
],
];
}
}
else
{
$url
=
node_authlink_get_url
(
$node
,
$op
);
if
(
$url
)
{
// @todo: use a table instead.
$form
[
'link_'
.
$op
]
=
[
'#type'
=>
'item'
,
'#markup'
=>
"<p><strong>
$op
</strong>:
$url
</p>"
,
];
}
}
}
if
(
node_authlink_load_authkey
(
$node
->
id
()))
{
...
...
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