Problem/Motivation
As we march towards better recipe authoring tools, the next logical step in having a good default content export system is the ability to export all content of a particular entity type and bundle.
Possible uses for this:
- Let's say you make 10 sample blog posts in a site, and you want to export all of them into your blog recipe.
- Or maybe you set up a megamenu with 30 links in it, and you want to export that entire menu in one fell swoop.
- You want to export a collection of image media.
I'm sure we can think of others!
Proposed resolution
Core already has all of the necessary infrastructure for this. We just need an interface to do it.
So, let's alter the existing content:export command to make the entity ID optional. That opens use cases like:
- To export all content:
content:export node --dir=content - To export all content, and its dependencies:
content:export node --with-dependencies --dir=content - ...of a particular bundle:
content:export node --bundle=blog --dir=my-blog
For now, let's keep requiring the entity type ID as an argument -- only one entity type at a time can be exported. Maybe in a follow-up we can expand that to automatically export all content, indiscriminately. But that feels like a separate scope.
API changes
No API changes should be necessary. Combined with an entity query, core's default content exporter is already capable of this.
Release notes snippet
TBD
Issue fork drupal-3547119
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:
- export-multiple-content-entities
changes, plain diff MR !13309
- 3547119-add-a-command
compare
Comments
Comment #2
thejimbirch commentedMoving the default content system.
With the default_content contrib module, we could export the following types.
node
taxonomy_term
file
media
menu_link_content
block_content
shortcut
I believe all except for file could have a bundle type and would be beneficial for recipe creators.
Comment #3
thejimbirch commentedAdding an non-working issue in the contrib module for reference.
Comment #4
phenaproximaComment #8
wotnakCreated MR !13309 with following changes:
php core/scripts/drupal content:export entity_type_id --dir=...--diroption is required--with-dependenciesoption is provided, then also exports dependenciesphp core/scripts/drupal content:export node --dir=./contentphp core/scripts/drupal content:export entity_type_id --bundle=entity_bundle_id --dir=...--diroption is required--with-dependenciesoption is provided, then also exports dependenciesphp core/scripts/drupal content:export node --bundle=article --dir=./contentphp core/scripts/drupal content:export --dir=...--diroption is required--with-dependenciesoption is ignoredphp core/scripts/drupal content:export --dir=./content--verboseor its shortcuts), instead of the progress bar, information about each exported entity is shownComment #9
wotnakComment #10
phenaproximaThis seems like a great start -- and bless you for writing tests!!! -- but it's a little hard to read and understand, overall, because of the complexity. I think we might want to scale back a few things, at least for now:
Comment #11
wotnak@phenaproxima Progress bar and option to export all content entities removed.
Comment #12
phenaproximaDamn you are fast. Assigning to myself to review.
Comment #13
phenaproximaReviewed, and looks better and better -- I think this will be even better if we use a generator function to yield the entities to export, rather than trying to load them all at once and do an array_chunk() on them. There is also more verbosity than is generally needed, and some changes which don't add anything to the patch and should be reverted. But it's shaping up!
Comment #14
wotnakPushed changes including refactoring to a generator function and added replies to all comments.
Comment #15
ironnuts commentedHere is the output of the test-only test. Seems good:
Comment #16
smustgrave commentedSo did some manual testing.
On a fresh 11.x install
Standard profile install
Created a few Articles and Basic page content
Ran
php core/scripts/drupal content:export node --dir=my-content --bundle=pageVerified ONLY Basic pages were exported
Did the same for Articles
Appears to be working as expected!
Tagging for a CR though.
Leaving in review for others
Comment #17
smustgrave commentedbeen almost a week to keep it moving moving to NW for the CR. I'll keep an eye out for it to come back around and ping in slack
Comment #18
phenaproximaRather than a new CR, let's update the existing one: https://www.drupal.org/node/3533854
Comment #19
nicxvan commentedThat might make sense, want to draft the change here so it's just a copy and paste when this gets in?
Comment #20
phenaproximaSimplified this a bit and added more test coverage. Incidentally, now that it's wrapping around a simple entity query, we get "export all entities of a type" for free. So I added a test of that. I also allowed multiple
--bundleoptions to be passed.Comment #21
phenaproximaUpdated the change record with usage examples for this.
Comment #23
thejimbirch commentedEverything is green, Change record updated, even better tests, and all of entity type!
Marking as RTBC.
Go team Default Content!
Comment #24
alexpottCommitted and pushed 3bfa87d35a5 to 11.x and 44d2c86e5cb to 11.3.x. Thanks!
Can we update the CR please. Once the CR update has been done this can be set to fixed.
Comment #27
alexpottOh @phenaproxima had already made the changes even though this hadn't been merged... risky and interesting :) ... doesn't matter now!
Comment #29
phenaproximaOpened #3554978: ContentExportCommand::loadEntities() should use loadByProperties().
Comment #31
gábor hojtsy