\Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::save should call ::validate() on the entity

Created on 17 May 2018, over 6 years ago
Updated 9 February 2024, 7 months ago

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

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated less than a minute ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand DanielVeza Brisbane, AU

    This came up as a daily target for the Bug smash initiative. I've checked out the code and the entity isn't validated before it's saved.

Production build 0.71.5 2024