By phenaproxima on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.3.x
Introduced in version:
11.3.0
Issue links:
Description:
Default content is now exported without the created field by default. The reasoning is that it's confusing, upon import, to see content that was created at an arbitrary time, rather than the time of import (which, as far as Drupal is concerned, is the time the content was created).
If you want to include created times in default content, you can do this with an event subscriber that marks the fields as included:
use Drupal\Core\DefaultContent\PreExportEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Subscribes to default content-related events.
*
* @internal
* Event subscribers are internal.
*/
class DefaultContentSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
return [PreExportEvent::class => 'preExport'];
}
/**
* Reacts before an entity is exported.
*
* @param \Drupal\Core\DefaultContent\PreExportEvent $event
* The event object.
*/
public function preExport(PreExportEvent $event): void {
// To automatically export all `created` fields:
foreach ($event->entity->getFieldDefinitions() as $field_definition) {
if ($field_definition->getType() === 'created') {
$event->setExportable($field_definition->getName());
}
}
// To only export a specific one:
if ($event->entity->getEntityTypeId() === 'node') {
$event->setExportable('created');
}
}
}
Impacts:
Module developers