- Issue created by @bkosborne
- π³π±Netherlands joshahubbers
This is a tricky one indeed. It is not very hard to intercept the form and prevent the published setting being set to false, but how will this behave in automated workflows? I have to think about this a little.
- πΊπΈUnited States bkosborne New Jersey, USA
We ended up doing this:
/** * Implements hook_entity_field_access(). */ function HOOK_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { $accessResult = AccessResult::neutral(); if ($operation === "edit" && $items) { $entity = $items->getEntity(); // Prevent users from unpublishing a node that's set their homepage. if ($field_definition->getName() === 'status' && $entity instanceof NodeInterface && $items->getEntity()->status->value) { $isHomePage = /* function call to check if the entity is the homepage */ $accessResult = AccessResult::forbiddenIf($isHomePage, 'The homepage may not be unpublished.'); } return $accessResult; }
This removes the ability to unpublish the page from the UI, like when editing a node (the publish checkbox is removed) or using bulk actions on the main content list view.
- π³π±Netherlands joshahubbers
Hm, nice, I will have a look at inserting it in the module and write some tests for it.
- π³π±Netherlands joshahubbers
Did you use this in combination with workflows?
- πΊπΈUnited States bkosborne New Jersey, USA
I haven't tested it with workflows, but I think it wouldn't work with content moderation.
- π³π±Netherlands joshahubbers
Hm, I did add your suggestion to the module, but accidently committed it in the dev branch in stead of in the issue fork. If you want to test the implementation in the dev-branch, it would be great...
- Status changed to Fixed
7 months ago 6:18am 27 June 2024 Automatically closed - issue fixed for 2 weeks with no activity.