class DefaultContentSubscriber
Same name in this branch
- 11.x core/modules/media/src/EventSubscriber/DefaultContentSubscriber.php \Drupal\media\EventSubscriber\DefaultContentSubscriber
- 11.x core/modules/layout_builder/src/EventSubscriber/DefaultContentSubscriber.php \Drupal\layout_builder\EventSubscriber\DefaultContentSubscriber
- 11.x core/modules/content_moderation/src/EventSubscriber/DefaultContentSubscriber.php \Drupal\content_moderation\EventSubscriber\DefaultContentSubscriber
- 11.x core/modules/link/src/EventSubscriber/DefaultContentSubscriber.php \Drupal\link\EventSubscriber\DefaultContentSubscriber
Subscribes to default content-related events.
@internal Event subscribers are internal.
Hierarchy
- class \Drupal\path\EventSubscriber\DefaultContentSubscriber extends \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of DefaultContentSubscriber
File
-
core/
modules/ path/ src/ EventSubscriber/ DefaultContentSubscriber.php, line 18
Namespace
Drupal\path\EventSubscriberView source
class DefaultContentSubscriber implements EventSubscriberInterface {
public function __construct(protected readonly EntityFieldManagerInterface $entityFieldManager) {
}
/**
* {@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 {
$event->setCallback('field_item:path', function (PathItem $item) : array {
$values = $item->getValue();
// Never export the path ID; it is recreated on import.
unset($values['pid']);
return $values;
});
// Despite being computed, export path fields anyway because, even though
// they're undergirded by path_alias entities, they're not true entity
// references and therefore aren't portable.
foreach ($this->entityFieldManager
->getFieldMapByFieldType('path') as $path_fields_in_entity_type) {
foreach (array_keys($path_fields_in_entity_type) as $name) {
$event->setExportable($name, TRUE);
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
DefaultContentSubscriber::getSubscribedEvents | public static | function | |
DefaultContentSubscriber::preExport | public | function | Reacts before an entity is exported. |
DefaultContentSubscriber::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.