Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
#2282519: Add content dependency information to configuration entities adds the ability for configuration to depend on content. However when importing configuration there is no way of creating the content that is depended on at the same time.
Proposed resolution
Add a step to the ConfigImporter that determines if there are any missing content dependencies and fire an event to allow contrib modules to respond and create the configuration.
Remaining tasks
Write patch
User interface changes
None
API changes
None - should be all additions
Comment | File | Size | Author |
---|---|---|---|
#37 | 2361423-swentel.37.patch | 21.71 KB | alexpott |
#37 | 30-37-interdiff.txt | 4.05 KB | alexpott |
#30 | interdiff.txt | 706 bytes | dixon_ |
#30 | 2361423-swentel.30.patch | 20.81 KB | dixon_ |
#29 | 2361423-swentel.29.patch | 20.82 KB | alexpott |
Comments
Comment #1
alexpottPostponing on #2282519: Add content dependency information to configuration entities
Comment #2
alexpottWe can do this now...
Comment #3
xjmComment #4
larowlanworking on this
Comment #5
alexpottHere's some work I already had done on this - needs tests though.
Comment #6
alexpottComment #7
larowlanHere's what I have, the test fails and I'm not sure how to test the context handling (batch).
Comment #8
larowlanso yours is way better than mine ;)
Comment #9
larowlanOne thing mine does is make ConfigImporter::getProcessedConfigurations useful, making it contain the config objects instead of the keys. We have no calls to that method in core (tests or otherwise) so that's most likely why - at present I think it doesn't really help anyone who listens to a ConfigImporterEvent.
Comment #10
dawehner@larowlan
I don't get why you reimplemented the feature in a different way. The advantage of the proposal of alexpott is that
you can recursivly resolve content dependencies, which is kind of helpful for entity references and what not.
nice one :)
It seems a bit odd to use FALSE and not just NULL
Does this really has to be a batch context? Is the system really built in a way to rely on something like a batch process? It would be really helpful to describe what is part of the
$context
, currently you as a user would have no clue what is in here.You don't test 'hi_there' at the moment.
Comment #11
larowlanSorry - should have said that @alexpott and I spoke on irc and realised we were both working on it at the same time - so we decided to put our patches up and then join forces and iterate from there.
I think @alexpott's is better too - but I like the changes to getProcessedConfigurations in mine, but no reason that can't go in a new issue
larowlan-- no idea what happened there but tipping wrong window was open :)
Comment #12
alexpott@larowlan the issue with getProcessedConfigurations() actually keeping a reference to the config means that all config is loaded on all steps of the batch - and possibly could go stale if there are side effects.
Comment #13
larowlanAh, so maybe we just need more documentation of how to get the objects from the event subscriber
Comment #17
isntall CreditAttribution: isntall commentedPatch from comment 7, 2361423-content-config-sync.5.patch, does not seem to pass the testbot checks, and it doesn't seem to fail properly either. Please reroll.
Comment #18
alexpottThe patch from #5 rerolled. @isntall core generally is self-service :) see http://drupal.org/patch/reroll
Comment #19
dawehnerOh nice, you can already add your own steps in contrib
What about using "FinalMissingContentSubscriber" as name?
... mh, so 1024 is a pretty high priority, I think you wanted to use -1024
Wrong variable name, probably.
From an API point of view, I think its wrong to stop always after the first resolveMissingContent call. Doesn't stopPropagation much more belongs into EventSubscriber?
Comment #20
yched CreditAttribution: yched commentedSame remarks as @dawehner :
- EventSubscriber is a bit short / non-telling
- seems surprising to stop propagation on the first entity being resolved ?
Nitpick : the whole method could be a bit leaner if it started by extracting the piece of the $context it's going to use for its processing, like
$sandbox = &$context['sandbox']['config'];
instead of fully dereferencing it again and again ?
Comment #21
dawehner.
Comment #22
larowlanfixes #19 and #20 plus a re-roll
Comment #23
swentel CreditAttribution: swentel commentedrerolled
Comment #24
dixon_Let's replace
()
with a.
here :)The docs seems wrong here since we no longer stop propagation here.
Agreed, I don't think we need to do anything here. So let's remove the
else
block here?Comment #27
alexpottPatches addresses everything in #24 and adds a test implementation of an event listener and uses it to test :)
Comment #28
jibranIf we are passing all the missing content in one go why would we need a sandbox? Are we missing some kind of array_slice here?
I think we can but it has to be a different loop. We can create an array of uuids per entity_type and then load it in next loop using loadByProperties() or see
EntityReferenceFieldItemList::processDefaultValue()
for similar kind of implementation.Comment #29
alexpottre #28
Comment #30
dixon_Code looks good. I'll be working on a proof-of-concept implementation in Deploy this week at DrupalCon that utilizes this.
Marking this as RTBC, with a very minor documentation fix to the patch (please don't give me commit credit because I haven't really worked on the patch itself).
Comment #31
dixon_Comment #33
alexpottUnrelated fail in Drupal\locale\Tests\LocaleJavascriptTranslationTest.
Comment #35
alexpottComment #36
catchIt's not clear from me what happens if there's no subscriber to deal with the missing content? Could this get stuck?
Oh here it is!
However I didn't immediately see test coverage that covers this case (i.e. that the final subscriber successfully removes content depenencies when nothing else has) - or did I miss it?
Comment #37
alexpott@catch well there is implicit coverage in things like ConfigImportAllTest but I've added explicit coverage in the attached patch.
Comment #38
catchThat looks better. Committed/pushed to 8.0.x, thanks!