class EntitySubqueuePreSave in Acquia Content Hub 8.2
Handles entity subqueue import failure.
@package Drupal\acquia_contenthub_subscriber\EventSubscriber\PreEntitySave
Hierarchy
- class \Drupal\acquia_contenthub_subscriber\EventSubscriber\PreEntitySave\EntitySubqueuePreSave implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of EntitySubqueuePreSave
1 file declares its use of EntitySubqueuePreSave
- EntitySubqueuePreSaveTest.php in tests/
src/ Kernel/ EventSubscriber/ PreEntitySave/ EntitySubqueuePreSaveTest.php
1 string reference to 'EntitySubqueuePreSave'
- acquia_contenthub_subscriber.services.yml in modules/
acquia_contenthub_subscriber/ acquia_contenthub_subscriber.services.yml - modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.services.yml
1 service uses EntitySubqueuePreSave
File
- modules/
acquia_contenthub_subscriber/ src/ EventSubscriber/ PreEntitySave/ EntitySubqueuePreSave.php, line 15
Namespace
Drupal\acquia_contenthub_subscriber\EventSubscriber\PreEntitySaveView source
class EntitySubqueuePreSave implements EventSubscriberInterface {
/**
* The entity subqueue.
*
* @var string
*/
const ENTITY_SUBQUEUE = 'entity_subqueue';
/**
* The module handler.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* EntitySubqueuePreSave constructor.
*
* @param \Drupal\Core\Database\Connection $database
* Database connection.
*/
public function __construct(Connection $database) {
// Using \Drupal::entityTypeManager() do to caching of the instance in
// some services. Looks like a core bug.
$this->entityTypeManager = \Drupal::entityTypeManager();
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::PRE_ENTITY_SAVE] = [
'onPreEntitySave',
80,
];
return $events;
}
/**
* Deletes entity subqueue if it's already created with diff UUID.
*
* @param \Drupal\acquia_contenthub\Event\PreEntitySaveEvent $event
* The pre entity save event.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function onPreEntitySave(PreEntitySaveEvent $event) {
if ($event
->getEntity()
->getEntityTypeId() !== self::ENTITY_SUBQUEUE) {
return;
}
$uuid = $event
->getEntity()
->uuid();
$subqueue_id = $event
->getEntity()
->id();
$query = $this->database
->select(self::ENTITY_SUBQUEUE, 'es');
$query
->fields('es', [
'uuid',
]);
$query
->condition('name', $subqueue_id);
$query
->condition('queue', $subqueue_id);
$result = $query
->execute()
->fetchField();
if ($result && $uuid !== $result) {
$entity_subqueue = $this->entityTypeManager
->getStorage('entity_subqueue')
->load($subqueue_id);
$entity_subqueue
->delete();
$event
->stopPropagation();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntitySubqueuePreSave:: |
protected | property | The database connection. | |
EntitySubqueuePreSave:: |
protected | property | The module handler. | |
EntitySubqueuePreSave:: |
constant | The entity subqueue. | ||
EntitySubqueuePreSave:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
EntitySubqueuePreSave:: |
public | function | Deletes entity subqueue if it's already created with diff UUID. | |
EntitySubqueuePreSave:: |
public | function | EntitySubqueuePreSave constructor. |