class CdfVersionAttribute in Acquia Content Hub 8.2
Notates the metadata with a CDF version marker.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\CdfVersionAttribute implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of CdfVersionAttribute
1 string reference to 'CdfVersionAttribute'
1 service uses CdfVersionAttribute
File
- src/
EventSubscriber/ CdfAttributes/ CdfVersionAttribute.php, line 15
Namespace
Drupal\acquia_contenthub\EventSubscriber\CdfAttributesView source
class CdfVersionAttribute implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::POPULATE_CDF_ATTRIBUTES][] = [
'onPopulateAttributes',
100,
];
$events[AcquiaContentHubEvents::BUILD_CLIENT_CDF][] = [
'onBuildClientCdf',
100,
];
return $events;
}
/**
* Adds a version attribute to Cdf Objects.
*
* @param \Drupal\acquia_contenthub\Event\CdfAttributesEvent $event
* The event being dispatched.
*
* @throws \Exception
*/
public function onPopulateAttributes(CdfAttributesEvent $event) {
$entity = $event
->getEntity();
if ($entity instanceof TranslatableInterface) {
$cdf = $event
->getCdf();
$this
->setVersion($cdf);
}
}
/**
* Adds a version attribute to Cdf Objects.
*
* @param \Drupal\acquia_contenthub\Event\BuildClientCdfEvent $event
* The BuildClientCdfEvent object.
*/
public function onBuildClientCdf(BuildClientCdfEvent $event) {
$cdf = $event
->getCdf();
$this
->setVersion($cdf);
}
/**
* Internal function to set the version for a CDF.
*
* @param \Acquia\ContentHubClient\CDF\CDFObject $cdf
* A CDFObject instance.
*/
protected function setVersion(CDFObject $cdf) {
$metadata = $cdf
->getMetadata();
$metadata['version'] = 2;
$cdf
->setMetadata($metadata);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CdfVersionAttribute:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
CdfVersionAttribute:: |
public | function | Adds a version attribute to Cdf Objects. | |
CdfVersionAttribute:: |
public | function | Adds a version attribute to Cdf Objects. | |
CdfVersionAttribute:: |
protected | function | Internal function to set the version for a CDF. |