function _prevent_homepage_deletion_check in Prevent homepage deletion 8
Helper function that checks if the current user can delete this node.
Parameters
\Drupal\Core\Entity\EntityInterface $entity:
\Drupal\Core\Session\AccountInterface $account:
Return value
bool
1 call to _prevent_homepage_deletion_check()
File
- ./
prevent_homepage_deletion.module, line 56 - Code and functions for the Prevent homepage deletion module.
Code
function _prevent_homepage_deletion_check(EntityInterface $entity, AccountInterface $account) {
$candelete = TRUE;
$entity_id = $entity
->id();
$frontpage_id = 0;
$config = \Drupal::config('system.site');
$front_uri = $config
->get('page.front');
$params = Url::fromUri("internal:" . $front_uri)
->getRouteParameters();
if (!empty($params)) {
$entity_type = key($params);
$frontpage_id = $params[$entity_type];
}
if (\Drupal::service('path.matcher')
->isFrontPage() || $entity_id === $frontpage_id) {
// Check for permission.
if ($account
->hasPermission('delete_homepage_node')) {
$candelete = TRUE;
}
else {
$candelete = FALSE;
}
}
return $candelete;
}