Skip to content
Snippets Groups Projects
Commit ffdedab2 authored by Liam Morland's avatar Liam Morland
Browse files

ISTWCMS-4229: Prevent moderation of home page

This can only be done by users with permission 'bypass home page
protection'.
parent 640d7fad
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}
*/ */
......
...@@ -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