class HashCdfAttribute in Acquia Content Hub 8.2
Calculates a hash value of the entity and stores it as an attribute.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\HashCdfAttribute implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of HashCdfAttribute
1 file declares its use of HashCdfAttribute
- HashCdfAttributeTest.php in tests/
src/ Unit/ EventSubscriber/ CdfAttributes/ HashCdfAttributeTest.php
1 string reference to 'HashCdfAttribute'
1 service uses HashCdfAttribute
File
- src/
EventSubscriber/ CdfAttributes/ HashCdfAttribute.php, line 14
Namespace
Drupal\acquia_contenthub\EventSubscriber\CdfAttributesView source
class HashCdfAttribute implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::POPULATE_CDF_ATTRIBUTES][] = [
'onPopulateAttributes',
100,
];
$events[AcquiaContentHubEvents::BUILD_CLIENT_CDF][] = [
'onBuildClientCdf',
-100,
];
return $events;
}
/**
* On populate attributes.
*
* @param \Drupal\acquia_contenthub\Event\CdfAttributesEvent $event
* CDF attributes event.
*
* @throws \Exception
*/
public function onPopulateAttributes(CdfAttributesEvent $event) {
$cdf = $event
->getCdf();
$wrapper = $event
->getWrapper();
$cdf
->addAttribute('hash', CDFAttribute::TYPE_STRING, $wrapper
->getHash());
}
/**
* On Build ClientCdf.
*
* @param \Drupal\acquia_contenthub\Event\BuildClientCdfEvent $event
* The BuildClientCdfEvent object.
*
* @throws \Exception
*/
public function onBuildClientCdf(BuildClientCdfEvent $event) {
$cdf = $event
->getCdf();
$data = $cdf
->toArray();
unset($data['created'], $data['modified']);
$cdf
->addAttribute('hash', CDFAttribute::TYPE_KEYWORD, sha1(json_encode($data)));
$event
->stopPropagation();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HashCdfAttribute:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
HashCdfAttribute:: |
public | function | On Build ClientCdf. | |
HashCdfAttribute:: |
public | function | On populate attributes. |