Needs review
Project:
Default Content
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Dec 2016 at 15:06 UTC
Updated:
26 Jul 2025 at 00:21 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
yanniboi commentedComment #3
yanniboi commentedComment #4
rlmumfordCode here looks good to me. A simple but very useful patch.
Comment #5
jibranLet's add some tests.
Comment #6
larowlanJust me or is ExportEvent missing from the patch?
Not 100% certain we need this. If you need to alter the output, can't you add your own normalizer?
Either way, no harm in adding it though.
Comment #7
yanniboi commented@larowlan ExportEvent already exists. (http://cgit.drupalcode.org/default_content/tree/src/Event/ExportEvent.php)
Our main use case is that for some entities you may want to remove fields before the export. Also, they are purely fields that we want excluded from the export not excluded from serialization in general. Eg. entity reference to entities that are themselves not being exported.
Will have a look at tests when I get a chance.
Comment #8
yanniboi commentedComment #9
andrewbelcher commentedI've taken a look at the normalizer approach, e.g.
\Drupal\default_content\Normalizer\TermEntityNormalizer. It looks to me like this approach actually replaces the existing normalizer with the one default content provides, which feels like it has a couple drawbacks:Comment #10
andypostI agree that having an event is fine here instead of a tons of normalizers
Comment #11
r-mo commentedRerolling for current version, still need tests.
Comment #12
berdirI've recently created the 2.0.x branch, see the project page on all the improvements in the 2.0.x branch. Testing that and providing feedback would be very welcome. The 1.x branch isn't actively maintained and won't receive new features anymore, so I'm closing this and other issues as won't fix.
2.0.x currently doesn't have an extension mechanism, and I think we should move an event that is similar to that for export and import in the new \Drupal\default_content\Normalizer\ContentEntityNormalizer class, e.g. denormalize() and normalizeTranslation(). API changes are OK there, so we can remove the current events.
Comment #13
berdirComment #14
andypostOn other hand the
\Drupal\default_content\Normalizer\ContentEntityNormalizerusing Entity api under the hoodSo for each create already 2 hooks fired
- for
getStorage($entity_type->id())->create($values);hook_entity_create from\Drupal\Core\Entity\EntityStorageBase::create- for
$entity->addTranslation()hook_translation_create from\Drupal\Core\Entity\ContentEntityStorageBase::createTranslation()SO i'm +1 to just add documentation and maybe resurrect core issue about "third_party properties" for entities (like node has in_preview) to indicate that entity created while DC importing data (like config inSync)
Comment #17
marios anagnostopoulos commented@andypost in your suggestion from #14, are you referring to
https://www.drupal.org/project/drupal/issues/3052115 and https://www.drupal.org/project/drupal/issues/2329253 ?
Using the entity API might work for importing, but does not cover export cases.
I made an initial commit with the most basic solution to the issue, meaning I just added two new events, one for serialization and one for de-serialization.
I think the following points are things that need consideration.
ContentEntityNormalizer::normalizeTranslation, since I thought that the normalized translations could be processed in the default entity's event if needed.Comment #18
marios anagnostopoulos commentedComment #19
marios anagnostopoulos commentedChanging it to needs work, since we probably want to also allow adding dependencies via events, and this is not supported with the current pr
Comment #20
marios anagnostopoulos commentedI removed the evend name from the dispatching since we are using separate events for the import/export processes and added a brief documentation for the import event.
Comment #23
sickness29 commentedUpdated fork with recent changes from dev branch and also added unit test for new events
Comment #24
phenaproximaIt is worth noting that core now has a default content import/export system (the import part has been around since 10.3, and the exporter will be in 11.3.0). The core system dispatches a
PreExportEventandPreImportEvent, so it might worth integrating with the core system instead of adding these events to Default Content.See https://www.drupal.org/node/3533854 for more info on the export system, and https://www.drupal.org/node/3445169 for more on the recipe system (which is where the importer and its event were added).