class OrphanedEntitiesHandler in Acquia Content Hub 8.2
Discovers entities with given origin.
@package Drupal\acquia_contenthub\EventSubscriber\Unregister
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\Unregister\OrphanedEntitiesHandler implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of OrphanedEntitiesHandler
1 string reference to 'OrphanedEntitiesHandler'
1 service uses OrphanedEntitiesHandler
File
- src/
EventSubscriber/ Unregister/ OrphanedEntitiesHandler.php, line 15
Namespace
Drupal\acquia_contenthub\EventSubscriber\UnregisterView source
class OrphanedEntitiesHandler implements EventSubscriberInterface {
/**
* The client factory.
*
* @var \Drupal\acquia_contenthub\Client\ClientFactory
*/
protected $clientFactory;
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::ACH_UNREGISTER][] = [
'onDeleteWebhook',
];
return $events;
}
/**
* OrphanedFilterHandler constructor.
*
* @param \Drupal\acquia_contenthub\Client\ClientFactory $factory
* ACH Client Factory.
*/
public function __construct(ClientFactory $factory) {
$this->clientFactory = $factory;
}
/**
* Gathers information about orphaned entities.
*
* @param \Drupal\acquia_contenthub\Event\AcquiaContentHubUnregisterEvent $event
* The event being dispatched.
*
* @throws \Exception
*/
public function onDeleteWebhook(AcquiaContentHubUnregisterEvent $event) : void {
$client = $this->clientFactory
->getClient();
$origin = !empty($event
->getOriginUuid()) ? $event
->getOriginUuid() : $client
->getSettings()
->getUuid();
$list_entities = $client
->listEntities([
'origin' => $origin,
]);
$orphaned_entites = $list_entities['total'] <= 1 ? 0 : $list_entities['total'];
$event
->setOrphanedEntitiesAmount($orphaned_entites);
$event
->setOrphanedEntities($list_entities['data']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrphanedEntitiesHandler:: |
protected | property | The client factory. | |
OrphanedEntitiesHandler:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
OrphanedEntitiesHandler:: |
public | function | Gathers information about orphaned entities. | |
OrphanedEntitiesHandler:: |
public | function | OrphanedFilterHandler constructor. |