Problem/Motivation
All configuration entities have a status property and the base class provides \Drupal\Core\Config\Entity\ConfigEntityBase::enable()
, \Drupal\Core\Config\Entity\ConfigEntityBase::disable()
, \Drupal\Core\Config\Entity\ConfigEntityBase::setStatus()
and \Drupal\Core\Config\Entity\ConfigEntityBase::status()
.
Views supports disabling but user roles does not.
Proposed resolution
Decide what to do. It does not seem right that all configuration entities support disabling. For some configuration entity types like Views it makes sense. For some, like Filter formats is it an essential security feature. For others like user roles introducing support would cause quite a few headaches.
Questions:
- How can we prevent users from calling the API and expected something to change when it does not?
- What configuration entities should support disabling and how do we indicate this on the API level?
Entity type | Status? | Entity key |
---|---|---|
block | Supports being enabled/disabled | Yes |
block_content_type | No support | No |
comment_type | No support | No |
contact_form | No support | No |
editor | They are paired up with filter formats - tested in EditorFilterIntegrationTest::testTextFormatIntegration() |
No |
field_config | No support - adding support would raise dragons. | No |
field_storage_config | No support - adding support would raise dragons. | No |
filter_format | Supports being enabled/disabled. This is due to security and preventing filter format delete. | Yes |
image_style | No support | No |
configurable_language | No support | No |
language_content_settings | No support | No |
node_type | No support | No |
rdf_mapping | No support | No |
responsive_image_style | No support | No |
rest_resource_config | Support in \Drupal\rest\Routing\ResourceRoutes::alterRoutes() | No |
search_page | Yep lots of usages of ->status() in SearchPageAccessControlHandler::checkAccess() for example. |
Yes |
shortcut_set | No support | No |
action | No support | No |
menu | No support | No |
taxonomy_vocabulary | No support | No |
tour | No support | No |
user_role | No support - given this is permission and security related I think we should avoid this complexity. | No |
workflow | Tentative support in BundleModerationConfigurationForm::form() - also workflows with no status are disabled automatically - adding a state enables the workflow. |
No |
view | Supports being enabled/disabled | Yes |
date_format | No support | No |
entity_form_display | Looks like there is support in EntityDisplayRepository::getDisplayModeOptionsByBundle() |
Yes |
entity_form_mode | No support | No |
entity_view_display | Looks like there is support in EntityDisplayRepository::getDisplayModeOptionsByBundle() and comment_entity_view_display_presave() |
Yes |
entity_view_mode | No support | No |
base_field_override | No support - adding support would raise dragons. | No |
The documentation on \Drupal\Core\Config\Entity\ConfigEntityInterface::status() is interesting:
/**
* Returns whether the configuration entity is enabled.
*
* Status implementations for configuration entities should follow these
* general rules:
* - Status does not affect the loading of entities. I.e. Disabling
* configuration entities should only have UI/access implications.
* - It should only take effect when a 'status' key is explicitly declared
* in the entity_keys info of a configuration entity's annotation data.
* - Each entity implementation (entity/controller) is responsible for
* checking and managing the status.
*
* @return bool
* Whether the entity is enabled or not.
*/
public function status();
The current approach is to deprecate the methods on ConfigEntityBase/ConfigEntityInterface and implement a Trait and an Interface for the config entities that support a status.
Remaining tasks
Open a follow up to decide on workflow and status.
User interface changes
None.
API changes
Deprecate \Drupal\Core\Config\Entity\ConfigEntityInterface::enable(), ::disable(), ::setStatus() and ::status().
Introduce new \Drupal\Core\Config\Entity\StatusTrait and \Drupal\Core\Config\Entity\StatusInterface for config entities that support status to use.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#15 | 2872149-15.patch | 18.52 KB | alexpott |
#15 | 13-15-interdiff.txt | 1.34 KB | alexpott |
#13 | 2872149-13.patch | 18.15 KB | alexpott |
#13 | 9-13-interdiff.txt | 11.88 KB | alexpott |
#9 | 2872149-9.patch | 8.92 KB | alexpott |
Comments
Comment #2
alexpottComment #3
alexpottI'm pretty sure we should
Comment #4
alexpottI'm pretty sure we should... ... not get into disabled fields. Also disabled roles sounds problematic because security.
Also \Drupal\Core\Config\Entity\ConfigEntityListBuilder::getDefaultOperations() is interesting it does:
if ($this->entityType->hasKey('status')) {
And if this is true it adds enable and disable operations.
Comment #5
alexpottUpdated table to include which config entities have an entity key of status.
Comment #6
alexpottComment #7
alexpottComment #8
alexpottThe documentation on \Drupal\Core\Config\Entity\ConfigEntityInterface::status() is interesting - see issue summary.
Comment #9
alexpottHere's an idea of how to deprecate the methods so that support for status is opt-in rather than implicit and not complete or meaningful.
Comment #11
alexpottCompleting the table.
Comment #12
alexpottLooking at configuration entities and how the override status... what's up Webform... 'open' is not a bool :(
Comment #13
alexpottI was trying to deprecate setStatus in #9 too in favour of using the more expressive ->disable() and ->enable() but that just forces out-of-scope changes. Patch adds an interface for things implementing StatusTrait and fixes the problems with EntityDisplayBase using a NULL default value for a Boolean property.
Comment #15
alexpottUghs... #13 work on PHP7 but traits and inheritance has had some fixes for PHP7. So we can only move the property to the trait in Drupal 9.
Comment #16
alexpottComment #17
dawehnerWe should really explain them that they should check the interface before calling this function. I think this deprecation method is not obvious for them.
I think we should mention whether we recommend to just hide the piece or whether you need to ensure that the code is not running which is related with this config entity.
Note: the bit about the status key is far less important than the bit about what the expected behaviour is.
I'm not longer 100% sure about this idea of chaining: ocramius.github.io/blog/fluent-interfaces-are-evil/
Comment #21
joachim CreditAttribution: joachim as a volunteer commentedSetting to needs work based on #17.