You are here

class ReferenceablePluginTypesSubscriber in Recurring Time Period 8

Registers our plugin type as refereceable by Commerce's plugin field.

This does require Commerce module to be present, and will just do nothing if it is not. (At least that's the plan! ;)

Hierarchy

Expanded class hierarchy of ReferenceablePluginTypesSubscriber

1 string reference to 'ReferenceablePluginTypesSubscriber'
recurring_period.services.yml in ./recurring_period.services.yml
recurring_period.services.yml
1 service uses ReferenceablePluginTypesSubscriber
recurring_period.referenceable_plugin_types_subscriber in ./recurring_period.services.yml
Drupal\recurring_period\EventSubscriber\ReferenceablePluginTypesSubscriber

File

src/EventSubscriber/ReferenceablePluginTypesSubscriber.php, line 16

Namespace

Drupal\recurring_period\EventSubscriber
View source
class ReferenceablePluginTypesSubscriber implements EventSubscriberInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Too early to check for commerce module with the module handler service.
    // Can't check for whether the CommerceEvents::REFERENCEABLE_PLUGIN_TYPES
    // constant is defined.
    // Check for the class that provides the constant instead.
    if (class_exists(CommerceEvents::class)) {
      return [
        CommerceEvents::REFERENCEABLE_PLUGIN_TYPES => 'onPluginTypes',
      ];
    }
    else {
      return [];
    }
  }

  /**
   * Registers our plugin types as referenceable.
   *
   * @param \Drupal\commerce\Event\ReferenceablePluginTypesEvent $event
   *   The event.
   */
  public function onPluginTypes(ReferenceablePluginTypesEvent $event) {
    $plugin_types = $event
      ->getPluginTypes();
    $plugin_types['recurring_period'] = $this
      ->t('Recurring period');
    $event
      ->setPluginTypes($plugin_types);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReferenceablePluginTypesSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ReferenceablePluginTypesSubscriber::onPluginTypes public function Registers our plugin types as referenceable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.