public function Panelizer::hasEntityPermission in Panelizer 8.4
Same name and namespace in other branches
- 8.5 src/Panelizer.php \Drupal\panelizer\Panelizer::hasEntityPermission()
- 8.3 src/Panelizer.php \Drupal\panelizer\Panelizer::hasEntityPermission()
Checks if a user has permission to perform an operation on an entity.
Parameters
string $op: The operation. Possible values include:
- "revert to default"
- "change content"
\Drupal\Core\Entity\EntityInterface $entity: The entity.
string $view_mode: The view mode.
\Drupal\Core\Session\AccountInterface|NULL $account: (optional) The user account to check; or the current user if omitted.
Return value
bool TRUE if the user has permission; FALSE otherwise.
Overrides PanelizerInterface::hasEntityPermission
File
- src/
Panelizer.php, line 635
Class
- Panelizer
- The Panelizer service.
Namespace
Drupal\panelizerCode
public function hasEntityPermission($op, EntityInterface $entity, $view_mode, AccountInterface $account = NULL) {
if (!$account) {
$account = $this->currentUser
->getAccount();
}
// Must be able to edit the entity.
if (!$entity
->access('update', $account)) {
return FALSE;
}
// Must have overrides enabled.
$panelizer_settings = $this
->getPanelizerSettings($entity
->getEntityTypeId(), $entity
->bundle(), $view_mode);
if (empty($panelizer_settings['custom'])) {
return FALSE;
}
// Check admin permission.
if ($account
->hasPermission('administer panelizer')) {
return TRUE;
}
// @todo: check field access too!
// if ($op == 'revert to default') {
// // We already have enough permissions at this point.
// return TRUE;
// }
return $this
->hasOperationPermission($op, $entity
->getEntityTypeId(), $entity
->bundle(), $account);
}