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
1cd166a0
Commit
1cd166a0
authored
Aug 23, 2018
by
David López
Browse files
Options
Downloads
Patches
Plain Diff
Added custom access function
parent
fe5c2b0f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
node_authlink.routing.yml
+1
-0
1 addition, 0 deletions
node_authlink.routing.yml
src/Form/NodeAuthlinkNodeForm.php
+21
-0
21 additions, 0 deletions
src/Form/NodeAuthlinkNodeForm.php
with
22 additions
and
0 deletions
node_authlink.routing.yml
+
1
−
0
View file @
1cd166a0
...
@@ -5,5 +5,6 @@ node_authlink.node_authlink_node_form:
...
@@ -5,5 +5,6 @@ node_authlink.node_authlink_node_form:
_title
:
'
Authlink'
_title
:
'
Authlink'
requirements
:
requirements
:
_permission
:
'
create
and
delete
node
authlinks'
_permission
:
'
create
and
delete
node
authlinks'
_custom_access
:
'
\Drupal\node_authlink\Form\NodeAuthlinkNodeForm::access'
options
:
options
:
_admin_route
:
TRUE
_admin_route
:
TRUE
This diff is collapsed.
Click to expand it.
src/Form/NodeAuthlinkNodeForm.php
+
21
−
0
View file @
1cd166a0
...
@@ -2,8 +2,11 @@
...
@@ -2,8 +2,11 @@
namespace
Drupal\node_authlink\Form
;
namespace
Drupal\node_authlink\Form
;
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\node\Entity\Node
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
...
@@ -71,4 +74,22 @@ class NodeAuthlinkNodeForm extends FormBase {
...
@@ -71,4 +74,22 @@ class NodeAuthlinkNodeForm extends FormBase {
}
}
/**
* Checks that node_authlink was enabled for this content type.
*
* @param \Drupal\Core\Session\AccountInterface $account
* @param $node
*
* @return \Drupal\Core\Access\AccessResultInterface
*/
public
function
access
(
AccountInterface
$account
,
$node
)
{
if
(
is_numeric
(
$node
))
{
$node
=
Node
::
load
(
$node
);
$enable
=
$this
->
config
(
'node_authlink.settings'
)
->
get
(
'enable'
);
if
(
isset
(
$enable
[
$node
->
bundle
()])
&&
$enable
[
$node
->
bundle
()])
{
return
AccessResult
::
allowed
();
}
}
return
AccessResult
::
forbidden
();
}
}
}
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