You are here

public function AddAnotherController::addAnotherAccess in Add Another 8

Takes the user to the node creation page for the type of a given node.

1 string reference to 'AddAnotherController::addAnotherAccess'
addanother.routing.yml in ./addanother.routing.yml
addanother.routing.yml

File

src/Controller/AddAnotherController.php, line 26

Class

AddAnotherController
Controller routines for Add another routes.

Namespace

Drupal\addanother\Controller

Code

public function addAnotherAccess(NodeInterface $node) {
  if (!$node
    ->access('create')) {
    return AccessResult::forbidden();
  }
  $config = \Drupal::config('addanother.settings');
  $account = \Drupal::currentUser();
  $type = $node
    ->getType();
  if (\Drupal::routeMatch()
    ->getRouteName() == 'entity.node.edit_form' && !$config
    ->get('tab_edit.' . $type)) {
    return AccessResult::forbidden();
  }
  if ($config
    ->get('tab.' . $type) && $account
    ->hasPermission('use add another')) {
    return AccessResult::allowed();
  }
  return AccessResult::forbidden();
}