Commit 1cd166a0 authored by akalam's avatar akalam

Added custom access function

parent fe5c2b0f
......@@ -5,5 +5,6 @@ node_authlink.node_authlink_node_form:
_title: 'Authlink'
requirements:
_permission: 'create and delete node authlinks'
_custom_access: '\Drupal\node_authlink\Form\NodeAuthlinkNodeForm::access'
options:
_admin_route: TRUE
......@@ -2,8 +2,11 @@
namespace Drupal\node_authlink\Form;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\Entity\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
......@@ -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();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment