Skip to content
Snippets Groups Projects
Commit 1cd166a0 authored by David López's avatar David López
Browse files

Added custom access function

parent fe5c2b0f
No related branches found
No related tags found
No related merge requests found
...@@ -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
...@@ -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();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment