Problem/Motivation
\Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::save
call $this->getEntity()->save()
but ::validate()
never called on the entity.
This means that the entity could be saved with invalid values.
This came up in discussing #2973382: [meta] Decide how Layout Builder should function with Content Moderation and Workspaces modules because the entity for instance could be in Archived moderation state where it can't be save unless the moderation state is change to either Published or Draft
No calling ::validate()
also means that you could not effectively but constraints on the layout field itself that would be in effect when saving the Layout both programmatically and through the UI. For instance you may want to add a field constraint that the layout can't have over 10 sections or that you can't place a custom "Header" block in any section except the top.
Proposed resolution
Call $this->getEntity()->validate()
before saving in \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::save()
and throw exceptions if any are found.
This means that both \Drupal\layout_builder\Controller\LayoutBuilderController::saveLayout()
would have to display and messages and not save.
\Drupal\layout_builder\Form\RevertOverridesForm
should also probably override validateForm
and call $this->getEntity()->validate()
directly.
Remaining tasks
Write patch and review
User interface changes
The user will be given error message if they try to save a layout when the entity does not validate.
API changes
None
Data model changes
None