You are here

public function ForwardAccessChecker::isAllowed in Forward 8

Same name and namespace in other branches
  1. 8.3 src/ForwardAccessChecker.php \Drupal\forward\ForwardAccessChecker::isAllowed()
  2. 8.2 src/ForwardAccessChecker.php \Drupal\forward\ForwardAccessChecker::isAllowed()

Checks whether a Forward link or form can be displayed on a given entity and view mode.

Parameters

array $settings: Array of settings.

\Drupal\Core\Entity\EntityInterface $entity: Entity for which the link is being built.

$view_mode: The view mode to check.

$entity_type: The entity_type to check if an entity is not available at the time the check needs to occur.

$bundle: The bundle to check if an entity is not available at the time the check needs to occur.

Return value

boolean Whether access is allowed or not

Overrides ForwardAccessCheckerInterface::isAllowed

File

src/ForwardAccessChecker.php, line 42

Class

ForwardAccessChecker
Defines a class for checking whether a Forward link or form can be diplayed within a given context.

Namespace

Drupal\forward

Code

public function isAllowed(array $settings, EntityInterface $entity = NULL, $view_mode = NULL, $entity_type = NULL, $bundle = NULL) {

  // Full and default are synonymous
  if ($view_mode == 'default') {
    $view_mode = 'full';
  }

  // Check permission
  $show = $this->currentUser
    ->hasPermission('access forward');

  // Check view mode
  if ($show && $view_mode) {
    $show = !empty($settings['forward_view_' . $view_mode]);
  }

  // Check entity type
  if ($show) {
    if ($entity) {
      $entity_type = $entity
        ->getEntityTypeId();
    }
    $show = $entity_type ? !empty($settings['forward_entity_' . $entity_type]) : FALSE;
  }

  // Check entity bundle
  if ($show) {
    if ($entity) {
      $bundle = $entity
        ->bundle();
    }
    $show = $entity_type && $bundle ? !empty($settings['forward_' . $entity_type . '_' . $bundle]) : FALSE;
  }
  return $show;
}