class NodeOptionPremiumHelper in Node Option Premium 8
API and helper methods.
Hierarchy
- class \Drupal\nopremium\NodeOptionPremiumHelper implements NodeOptionPremiumHelperInterface
Expanded class hierarchy of NodeOptionPremiumHelper
1 file declares its use of NodeOptionPremiumHelper
- NodeOptionPremiumHelperTest.php in tests/
src/ Unit/ NodeOptionPremiumHelperTest.php
1 string reference to 'NodeOptionPremiumHelper'
1 service uses NodeOptionPremiumHelper
File
- src/
NodeOptionPremiumHelper.php, line 12
Namespace
Drupal\nopremiumView source
class NodeOptionPremiumHelper implements NodeOptionPremiumHelperInterface {
/**
* {@inheritdoc}
*/
public function hasFullAccess(ContentEntityInterface $entity, AccountInterface $account) {
if (!$entity
->hasField('premium')) {
// Entity has no premium field, so no restricted access.
return TRUE;
}
if (empty($entity->premium->value)) {
// This is not a premium entity. Full access granted.
return TRUE;
}
// Check permissions.
if ($account
->hasPermission('administer nodes') || $account
->hasPermission('view full premium content of any type') || $account
->hasPermission('view full ' . $entity
->bundle() . ' premium content') || $entity
->access('update', $account)) {
return TRUE;
}
// Check if the account owns the entity.
if ($entity instanceof EntityOwnerInterface && $account
->isAuthenticated() && $account
->id() == $entity
->getOwnerId()) {
return TRUE;
}
// In all other cases, the user hasn't full access to the entity.
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NodeOptionPremiumHelper:: |
public | function |
Checks if the given user has full access to the given entity. Overrides NodeOptionPremiumHelperInterface:: |