Loading
3633767 — Store view mode selections in a revisionable base field on the host entity
ERVMS previously kept per-item view mode selections in the key/value store, keyed by
entity ID. Selections were therefore not revisioned (drafts, moderation, and reverts
lost them), shared by every place a referenced entity was used (e.g. one Paragraphs
Library item could not be "Media left" on one page and "Media right" on another), and
persisted via static "pending data" caches applied in insert/update hooks. This moves
storage to a revisionable, untranslatable ervms_view_modes base field on the entity
that owns the reference field, so selections travel with the revision being saved,
viewed, or reverted, and adds an upgrade path from key/value data plus a clean uninstall.
Change log:
- Added
ViewModeSelectionStoragebase field support:ervms_view_modesmap field (buildFieldDefinition(),ensureFieldStorage()), reads from the revision being rendered,setAllData()now sets the value on the entity object (caller saves), newmergeData(),prune(),pruneStoredData()andisSelectorField(), with a legacy key/value read/write fallback until updates have run - Added
EntityBaseFieldHooksimplementinghook_entity_base_field_info()keyed off the last-installed schema, so core still removes the storage when the module is uninstalled; registered it and the new services inentity_reference_view_mode_selector.services.yml - Updated
EntityReferenceViewModeSelectorHooks:entity_presavenow prunes stale selections (removed deltas, deleted fields, selector disabled) instead of applying pending data; addedfield_config_insert/updatehooks to install the base field on demand when the selector is enabled on a field (wired via LegacyHook in the .module) - Rewrote
ViewModeFormHandler: removed the pending-data caches and presave step; the form submit now runs first and copies selections straight onto the host entity and onto the paragraph objects in the Paragraphs widget state; addedresolveWidgetEntity()and publicextractFieldViewModes() - Added
hook_update_10101()inentity_reference_view_mode_selector.installto install the field on all entity types using ERVMS (and ones holding only legacy data), andpost_update_migrate_legacy_selectionsin.post_update.php, a batched migration using the newLegacySelectionMigratorservice, which writes directly to the field tables (no entity saves, so no new revisions, moderation transitions or notifications) into the default and latest revisions, drops orphaned records, and keeps any skipped records and the read fallback - Added
FormatterReverterservice andhook_uninstall()implementations in the main module andervms_paragraphsthat swap the ERVMS formatters back toentity_reference_entity_view/entity_reference_revisions_entity_view(keeping settings, including Layout Builder field blocks) and clear legacy key/value data EntityViewModeFormatterandParagraphViewModeFormatter: fall back to the formatter's view mode when a selected view mode no longer existservms_paragraphs_entity_embed: added.installthat installs the field on theembedded_paragraphsentity type; removed theentity_insert/entity_updatehooks and the pending-data logic inEmbeddedParagraphsFormHandler, which now reuses the main form handler to set selections on the wrapper and (nested) paragraphs before save, with the submit handler prepended to run before the form's own save handlers- Added kernel tests:
ErvmsKernelTestBase,ViewModeSelectionStorageTest,LegacyMigrationTestandUninstallTest - README: documented the new storage model, the update/migration behavior, the revised
data flow, the need to save after
set_all_data(), and uninstall steps
Closes #3633767