class ForwardAccessChecker in Forward 8
Same name and namespace in other branches
- 8.3 src/ForwardAccessChecker.php \Drupal\forward\ForwardAccessChecker
- 8.2 src/ForwardAccessChecker.php \Drupal\forward\ForwardAccessChecker
Defines a class for checking whether a Forward link or form can be diplayed within a given context.
Hierarchy
- class \Drupal\forward\ForwardAccessChecker implements ForwardAccessCheckerInterface
Expanded class hierarchy of ForwardAccessChecker
1 string reference to 'ForwardAccessChecker'
1 service uses ForwardAccessChecker
File
- src/
ForwardAccessChecker.php, line 11
Namespace
Drupal\forwardView source
class ForwardAccessChecker implements ForwardAccessCheckerInterface {
/**
* The current user service.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* Constructs a ForwardAccessChecker object.
*
* @param \Drupal\Core\Session\AccountProxyInterface
* The current user service.
*/
public function __construct(AccountProxyInterface $current_user) {
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'));
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ForwardAccessChecker:: |
protected | property | The current user service. | |
ForwardAccessChecker:: |
public static | function | ||
ForwardAccessChecker:: |
public | function |
Checks whether a Forward link or form can be displayed on a given entity and view mode. Overrides ForwardAccessCheckerInterface:: |
|
ForwardAccessChecker:: |
public | function | Constructs a ForwardAccessChecker object. |