You are here

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'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses CdfVersionAttribute
version.cdf.attribute in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\CdfVersionAttribute

File

src/EventSubscriber/CdfAttributes/CdfVersionAttribute.php, line 15

Namespace

Drupal\acquia_contenthub\EventSubscriber\CdfAttributes
View 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

Namesort descending Modifiers Type Description Overrides
CdfVersionAttribute::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CdfVersionAttribute::onBuildClientCdf public function Adds a version attribute to Cdf Objects.
CdfVersionAttribute::onPopulateAttributes public function Adds a version attribute to Cdf Objects.
CdfVersionAttribute::setVersion protected function Internal function to set the version for a CDF.