class ExistingEntity in Acquia Content Hub 8.2
Place existing entities into the dependency stack.
Hierarchy
- class \Drupal\acquia_contenthub_subscriber\EventSubscriber\EntityDataTamper\ExistingEntity implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ExistingEntity
1 string reference to 'ExistingEntity'
- 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 ExistingEntity
File
- modules/
acquia_contenthub_subscriber/ src/ EventSubscriber/ EntityDataTamper/ ExistingEntity.php, line 14
Namespace
Drupal\acquia_contenthub_subscriber\EventSubscriber\EntityDataTamperView source
class ExistingEntity implements EventSubscriberInterface {
/**
* The subscriber tracker.
*
* @var \Drupal\acquia_contenthub_subscriber\SubscriberTracker
*/
protected $tracker;
/**
* ExistingEntity constructor.
*
* @param \Drupal\acquia_contenthub_subscriber\SubscriberTracker $tracker
* Subscriber tracker.
*/
public function __construct(SubscriberTracker $tracker) {
$this->tracker = $tracker;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::ENTITY_DATA_TAMPER][] = [
'onDataTamper',
100,
];
return $events;
}
/**
* Tamper with CDF data before its imported.
*
* @param \Drupal\acquia_contenthub\Event\EntityDataTamperEvent $event
* The data tamper event.
*
* @throws \Exception
*/
public function onDataTamper(EntityDataTamperEvent $event) {
$cdf = $event
->getCdf();
foreach ($cdf
->getEntities() as $uuid => $object) {
// @todo we want to compare by hashes eventually.
$hash = $object
->getAttribute('hash')
->getValue()['und'];
$entity = $this->tracker
->getEntityByRemoteIdAndHash($uuid, $hash);
if ($entity) {
$wrapper = new DependentEntityWrapper($entity);
$wrapper
->setRemoteUuid($uuid);
$event
->getStack()
->addDependency($wrapper);
$this->tracker
->setStatusByUuid($uuid, SubscriberTracker::IMPORTED);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExistingEntity:: |
protected | property | The subscriber tracker. | |
ExistingEntity:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ExistingEntity:: |
public | function | Tamper with CDF data before its imported. | |
ExistingEntity:: |
public | function | ExistingEntity constructor. |