You are here

class BaseUrlAttribute in Acquia Content Hub 8.2

Adds base url to all CDF documents.

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\BaseUrlAttribute implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of BaseUrlAttribute

1 string reference to 'BaseUrlAttribute'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses BaseUrlAttribute
base_url.cdf.attribute in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\BaseUrlAttribute

File

src/EventSubscriber/CdfAttributes/BaseUrlAttribute.php, line 14

Namespace

Drupal\acquia_contenthub\EventSubscriber\CdfAttributes
View source
class BaseUrlAttribute implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::POPULATE_CDF_ATTRIBUTES][] = [
      'onPopulateAttributes',
      100,
    ];
    return $events;
  }

  /**
   * Adds base url to all CDF documents.
   *
   * @param \Drupal\acquia_contenthub\Event\CdfAttributesEvent $event
   *   The event being dispatched.
   *
   * @throws \Exception
   */
  public function onPopulateAttributes(CdfAttributesEvent $event) {
    $cdf = $event
      ->getCdf();
    $url = Url::fromUserInput("/", [
      'absolute' => TRUE,
    ]);
    $cdf
      ->addAttribute('base_url', CDFAttribute::TYPE_STRING, $url
      ->toString());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseUrlAttribute::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
BaseUrlAttribute::onPopulateAttributes public function Adds base url to all CDF documents.