Skip to content
Snippets Groups Projects
Commit f7fbc5e4 authored by Eric Bremner's avatar Eric Bremner
Browse files

Merge branch 'feature/ISTWCMS-4229-lkmorlan-protect-homepage' into '8.x-1.x'

ISTWCMS-4229: Prevent moderation of home page except by admin

See merge request !34
parents 6db4c581 ffdedab2
No related branches found
No related tags found
1 merge request!34ISTWCMS-4229: Prevent moderation of home page except by admin
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
namespace Drupal\uw_cfg_common\Form; namespace Drupal\uw_cfg_common\Form;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\uw_cfg_common\Service\UWService;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -54,6 +57,19 @@ class UwContentModerationForm extends ConfirmFormBase { ...@@ -54,6 +57,19 @@ class UwContentModerationForm extends ConfirmFormBase {
); );
} }
/**
* Access callback. No access for the home page, except by admin.
*
* @return object
* A AccessResult object.
*/
public function access(int $nid, AccountInterface $account): AccessResult {
if (UWService::nodeIsHomePage($nid) && !$account->hasPermission('bypass home page protection')) {
return AccessResult::forbidden();
}
return AccessResult::allowed();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -368,4 +368,19 @@ class UWService implements UWServiceInterface { ...@@ -368,4 +368,19 @@ class UWService implements UWServiceInterface {
} }
} }
/**
* Determine whether a node is the home page.
*
* @param int $nid
* A node ID.
*
* @return bool
* TRUE when the node is the home page, FALSE otherwise.
*/
public static function nodeIsHomePage(int $nid): bool {
$front_page_path = \Drupal::configFactory()->get('system.site')->get('page.front');
$node_alias = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $nid);
return $front_page_path === $node_alias;
}
} }
'access content access form': 'access content access form':
title: 'Access content access form' title: 'Access content access form'
description: 'Allows access to the content access form.' description: 'Allows access to the content access form.'
'bypass home page protection':
title: 'Bypass home page protection'
description: 'Allows taking actions that are not normally allowed for the home page, such as unpublishing.'
restrict access: true
...@@ -11,4 +11,5 @@ uw_content_moderation.form: ...@@ -11,4 +11,5 @@ uw_content_moderation.form:
_title: 'Content moderation' _title: 'Content moderation'
_form: '\Drupal\uw_cfg_common\Form\UwContentModerationForm' _form: '\Drupal\uw_cfg_common\Form\UwContentModerationForm'
requirements: requirements:
_custom_access: '\Drupal\uw_cfg_common\Form\UwContentModerationForm::access'
_permission: 'access content' _permission: 'access content'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment