Problem/Motivation
Child 3 of #3624396: Plan: Harden InstanceInterface, IslandInterface and DisplayBuildableInterface as public API before RC1, split in two: this one is InstanceInterface, child 3b the other interfaces. Needs #3627028: InstanceInterface: one failure style for the tree methods.
- Setting a whole tree goes through
setNewPresent(), a history term with two boolean flags, which returns nothing. Seven callers outside the instance, the submodules among them, use it, and each one callssave()right after, though it already saved. - The controllers save again after a mutator, 9 times: each mutator already saves.
isPublishedPresent()compares hashes that count node IDs, so it can answer "not published" wherehasUnpublishedChanges()finds no change.getUniqId()andgetContentHash()are static methods on the interface. The hash is written in three places, and the storage recomputes it on every save anyway.ensureCurrentTranslation()saves and may return another object, and says neither. Its comment names one translatable field, there are three.Instance::$currentUseris public, for one test.- Two mutators do not say that they save a revision, nor that on a translation a structural change reaches every language.
Proposed resolution
setSources(array $sources, string|\Stringable $log_message = ''): staticonInstanceInterface, normalizing and skipping an identical tree assetNewPresent()does with its default flags.setNewPresent()is removed fromHistoryInterface, and its seven callers move tosetSources(). The mutators share a private method that holds the two flags.- No extra
save()after a mutator orsetSources(), in the controllers and the submodules. Tests: one change, one revision. isPublishedPresent()returns!$this->hasUnpublishedChanges(). Test: an instance whose published sources lack the draft's node IDs is published present.getUniqId()andgetContentHash()leave the interface: they are static methods on a contract. They stay on theInstanceclass, internal, for the module's own callers. The storage alone writes the hash:postCreate()andcreateDisplayBuilderInstance()stop.getHash()andgetPublishedHash()say what each hash counts and when to use it.InstancesPanel::hasUnpublishedChanges()gets a@seeto the instance method, and a test for a reference whose instance is gone.ensureCurrentTranslation(): static, with an@return, and a docblock saying it saves and may return another object. Its comment names the translatable fields. Which language it should follow is its own issue, under #3615902: Plan: Translation support.Instance::$currentUserprivate.InstanceHistoryTestswitches users with the test trait'ssetCurrentUser().- Every mutator docblock says it saves a revision, which on a translation reaches every language when the structure changes.
Remaining tasks
- Update
display_builder_aiand the dev tools tosetSources(). - Write the change record, or extend the one of #3627028: InstanceInterface: one failure style for the tree methods.
User interface changes
None.
API changes
- New
InstanceInterface::setSources().HistoryInterface::setNewPresent()removed. getUniqId()andgetContentHash()removed fromInstanceInterface.ensureCurrentTranslation()returnsstatic.Instance::$currentUseris private.isPublishedPresent()ignores node IDs.
Data model changes
None.
Issue fork display_builder-3627284
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mogtofu33 commentedComment #3
pdureau commentedIf it is a RC blocker, it must be moved to next beta.
Comment #4
pdureau commentedComment #5
pdureau commentedProposal analysis
So
InstanceInterface::setSources()is becoming simpler replacement ofHistoryInterface::setNewPresent()without thecheck_hashandindexflags, and performing the entity save?It is great to simplify the
HistoryInterface, removing the last leftover of the old "steps" system.⚠️ However
HistoryInterface::setNewPresent()is already never called using thecheck_hashandindexflags outside ofInstanceentity internal calls and the relatedInstanceHistoryTest.So, before renaming/moving any public method, let's try to simply move
::setNewPresent()logic into a private::saveTree()method and remove the flags from the public API.⚠️ Also, it is a bit "disturbing" to make the entity save itself, especially in a "set field value" method. In Drupal, methods that change an entity normally just change it in memory and return $this; the caller decides when to call save(). So, this proposal go against the convention. I know we already do that 2 or 3 times in thge codebase, but is this the opportunity to remove them instead of consolidating them?
We can also remove comment(s) about https://redux.js.org/usage/implementing-undo-history because it is not the case anymore, since we moved to a revisionable content entity.
👌 OK. But do we still need keep both methods in this case ? I would advocate removing one.
👌 OK for removing
InstanceInterface::getUniqId()andInstanceInterface::getContentHash(), and leveragingEntityInterface::postCreate()and/or the Entity Storage. It looks more Drupally.⚠️ However,
::getContentHash()is also called from buildable plugins andInstanceRowStatus, so how can we do that without extending the storage interface? ASourcesHashTrait? It may also be the opportunity to removeInstanceRowStatuswhich is a curiosity only used by InstancesPanel.👌No opinion about that.
It would be nice to remove
InstanceInterface::ensureCurrentTranslation()all together, it looks a bit odd and I am surprised there is no existing mechanism in Drupal Core doing this kind of job. But I guess it is not possible.It is already the case as far as I know.
👌 Just a docblock change? OK.
Work
I will give a try.
Expected breaking changes:
HistoryInterface::setNewPresent()(or replace it byInstanceInterface::setSources())InstanceInterface::getUniqId()InstanceInterface::getContentHash()InstanceInterface:isPublishedPresent()or:hasUnpublishedChanges()?Instance::currentUserDisplayBuildableInterface::ensureCurrentTranslation()phpunit changes must be limited to:
Playwright tests must not be changed, not at all.
Comment #7
pdureau commentedFirst commit pushed.
Done
Done with
SourcesHashTraitused in:Instance::hasUnpublishedChanges()entity. Is it something to move toInstanceStorage?InstanceStorage, as expectedInstanceRowStatus, finally keptDisplayBuildablePluginBase, as expectedNext steps
There are 2 decisions to take:
HistoryInterface::setNewPresent()withInstanceInterface::setSources(), knowing it will add around+100/-100changes in an already heavy MR.I would advise to remove
::hasUnpublishedChanges(), because less usage in the codebase:Comment #12
pdureau commentedNew MR: https://git.drupalcode.org/project/display_builder/-/merge_requests/538
I played it safe, picking the last disruptive naming change options (
::setNewPresent()instead of::setSource(),::isPublishedPresent()instead of::hasUnpublishedChanges()) while targeting the goals of the ticket (as far as I understood them):Interface changes:
HistoryInterface::setNewPresent()InstanceInterface::getUniqId()InstanceInterface::getContentHash():hasUnpublishedChanges()Instance::currentUserDisplayBuildableInterface::ensureCurrentTranslation()Comment #13
csakiistvanComment #14
csakiistvan✅ Tested and works — rebased MR !538 locally on 1.0.x (no conflicts), applied it, rebuilt caches and re-ran the publication check on an instance whose draft and published sources differ only in node IDs:
isPublishedPresent()went fromFALSEtoTRUEand the status reads "Published". The contradiction between the two publication checks is gone.Code review - No caller outside the instance still calls
save()right aftersetNewPresent().Comment #15
pdureau commentedThanks István.
Jean, what do you think of the stance I took in #12 ("I played it safe, picking the last disruptive naming change options")?
Comment #16
mogtofu33 commentedI agree with changes from #3627284-12: InstanceInterface: setSources() instead of setNewPresent(), one save per change, the hashes, rebased on 1.0.x, which removed two more save() calls in the hooks that replaced EntityViewDisplayTrait.
Change record for next release in my list.
Thanks for the work.
Comment #19
pdureau commentedShipped in beta10 release.