ForwardAccessChecker.php in Forward 8.3
File
src/ForwardAccessChecker.php
View source
<?php
namespace Drupal\forward;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountProxyInterface;
class ForwardAccessChecker implements ForwardAccessCheckerInterface {
protected $currentUser;
public function __construct(AccountProxyInterface $current_user) {
$this->currentUser = $current_user;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'));
}
public function isAllowed(array $settings, EntityInterface $entity = NULL, $view_mode = NULL, $entity_type = NULL, $bundle = NULL) {
if ($view_mode == 'default') {
$view_mode = 'full';
}
$show = $this->currentUser
->hasPermission('access forward');
if ($show && $view_mode) {
$show = !empty($settings['forward_view_' . $view_mode]);
}
if ($show) {
if ($entity) {
$entity_type = $entity
->getEntityTypeId();
}
$show = $entity_type ? !empty($settings['forward_entity_' . $entity_type]) : FALSE;
}
if ($show) {
if ($entity) {
$bundle = $entity
->bundle();
}
$show = $entity_type && $bundle ? !empty($settings['forward_' . $entity_type . '_' . $bundle]) : FALSE;
}
return $show;
}
}
Classes
Name |
Description |
ForwardAccessChecker |
Defines a class for checking whether a Forward link or form can be diplayed within a given context. |