class PreImportEvent
Event dispatched before default content is imported.
Subscribers to this event should avoid modifying content, because it is probably about to change again. This event is best used for tasks like notifications, logging, or updating a value in state. It can also be used to skip importing certain entities, identified by their UUID.
Hierarchy
- class \Drupal\Core\DefaultContent\PreImportEvent extends \Symfony\Contracts\EventDispatcher\Event
Expanded class hierarchy of PreImportEvent
1 file declares its use of PreImportEvent
- ContentImportTest.php in core/
tests/ Drupal/ FunctionalTests/ DefaultContent/ ContentImportTest.php
File
-
core/
lib/ Drupal/ Core/ DefaultContent/ PreImportEvent.php, line 17
Namespace
Drupal\Core\DefaultContentView source
final class PreImportEvent extends Event {
/**
* Entity UUIDs that should not be imported.
*
* @var string[]
*/
private array $skip = [];
/**
* Constructs a PreImportEvent object.
*
* @param \Drupal\Core\DefaultContent\Finder $finder
* The content finder, which has information on the entities to create
* in the necessary dependency order.
* @param \Drupal\Core\DefaultContent\Existing $existing
* What the importer will do when importing an entity that already exists.
*/
public function __construct(Finder $finder, Existing $existing) {
}
/**
* Adds an entity UUID to the skip list.
*
* @param string $uuid
* The UUID of an entity that should not be imported.
* @param string|\Stringable|null $reason
* (optional) A reason why the entity is being skipped. Defaults to NULL.
*
* @throws \InvalidArgumentException
* If the given UUID is not one of the ones being imported.
*/
public function skip(string $uuid, string|\Stringable|null $reason = NULL) : void {
if (array_key_exists($uuid, $this->finder->data)) {
$this->skip[$uuid] = $reason;
}
else {
throw new \InvalidArgumentException("Content entity '{$uuid}' cannot be skipped, because it is not one of the entities being imported.");
}
}
/**
* Returns the list of entity UUIDs that should not be imported.
*
* @return string|\Stringable|null[]
* An array whose keys are the UUIDs of the entities that should not be
* imported, and the values are either a short explanation of why that
* entity was skipped, or NULL if no explanation was given.
*/
public function getSkipList() : array {
return $this->skip;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
PreImportEvent::$skip | private | property | Entity UUIDs that should not be imported. |
PreImportEvent::getSkipList | public | function | Returns the list of entity UUIDs that should not be imported. |
PreImportEvent::skip | public | function | Adds an entity UUID to the skip list. |
PreImportEvent::__construct | public | function | Constructs a PreImportEvent object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.