class ExportMetadata
Collects metadata about an entity being exported.
@internal This API is experimental.
Hierarchy
- class \Drupal\Core\DefaultContent\ExportMetadata
Expanded class hierarchy of ExportMetadata
2 files declare their use of ExportMetadata
- DefaultContentSubscriber.php in core/
modules/ layout_builder/ src/ EventSubscriber/ DefaultContentSubscriber.php - DefaultContentSubscriber.php in core/
modules/ link/ src/ EventSubscriber/ DefaultContentSubscriber.php
File
-
core/
lib/ Drupal/ Core/ DefaultContent/ ExportMetadata.php, line 15
Namespace
Drupal\Core\DefaultContentView source
final class ExportMetadata {
/**
* The collected export metadata.
*/
private array $metadata = [
'version' => '1.0',
];
public function __construct(ContentEntityInterface $entity) {
$this->metadata['entity_type'] = $entity->getEntityTypeId();
$this->metadata['uuid'] = $entity->uuid();
$entity_type = $entity->getEntityType();
if ($entity_type->hasKey('bundle')) {
$this->metadata['bundle'] = $entity->bundle();
}
if ($entity_type->hasKey('langcode')) {
$this->metadata['default_langcode'] = $entity->language()
->getId();
}
}
/**
* Returns the collected metadata as an array.
*
* @return array
* The collected export metadata.
*/
public function get() : array {
return $this->metadata;
}
/**
* Adds a dependency on another content entity.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity we depend upon.
*/
public function addDependency(ContentEntityInterface $entity) : void {
$uuid = $entity->uuid();
if ($uuid === $this->metadata['uuid']) {
throw new \LogicException('An entity cannot depend on itself.');
}
$this->metadata['depends'][$uuid] = $entity->getEntityTypeId();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ExportMetadata::$metadata | private | property | The collected export metadata. |
ExportMetadata::addDependency | public | function | Adds a dependency on another content entity. |
ExportMetadata::get | public | function | Returns the collected metadata as an array. |
ExportMetadata::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.