Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
node_authlink
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
node_authlink
Commits
e29e7a69
Commit
e29e7a69
authored
Oct 22, 2018
by
David López
Browse files
Options
Downloads
Patches
Plain Diff
SP-832199932200423
: Added User interface for viewing authlinks for revisions.
parent
69a055a0
Branches
Branches containing commit
Tags
8.x-1.0
8.x-1.0-alpha1
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
node_authlink.module
+16
-4
16 additions, 4 deletions
node_authlink.module
src/Form/NodeAuthlinkNodeForm.php
+74
-7
74 additions, 7 deletions
src/Form/NodeAuthlinkNodeForm.php
with
90 additions
and
11 deletions
node_authlink.module
+
16
−
4
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'
:
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
],
]);
...
...
This diff is collapsed.
Click to expand it.
src/Form/NodeAuthlinkNodeForm.php
+
74
−
7
View file @
e29e7a69
...
...
@@ -69,17 +69,84 @@ class NodeAuthlinkNodeForm extends FormBase {
if
(
!
$op
)
{
continue
;
}
// 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'
=>
'
markup
'
,
'#type'
=>
'
item
'
,
'#markup'
=>
"<p><strong>
$op
</strong>:
$url
</p>"
,
];
}
}
}
if
(
node_authlink_load_authkey
(
$node
->
id
()))
{
$form
[
'delete'
]
=
[
'#type'
=>
'submit'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment