You are here

abstract class EdgeEntityEventDeriverBase in Apigee Edge 8

Rules event deriver for Apigee Edge entity types.

Hierarchy

Expanded class hierarchy of EdgeEntityEventDeriverBase

File

modules/apigee_edge_actions/src/Plugin/RulesEvent/EdgeEntityEventDeriverBase.php, line 34

Namespace

Drupal\apigee_edge_actions\Plugin\RulesEvent
View source
abstract class EdgeEntityEventDeriverBase extends DeriverBase implements EdgeEntityEventDeriverInterface {
  use StringTranslationTrait;

  /**
   * The apigee app entity type manager service.
   *
   * @var \Drupal\apigee_edge_actions\ApigeeActionsEntityTypeHelperInterface
   */
  protected $edgeEntityTypeManager;

  /**
   * AppEventDeriver constructor.
   *
   * @param \Drupal\apigee_edge_actions\ApigeeActionsEntityTypeHelperInterface $edge_entity_type_manager
   *   The apigee app entity type manager service.
   */
  public function __construct(ApigeeActionsEntityTypeHelperInterface $edge_entity_type_manager) {
    $this->edgeEntityTypeManager = $edge_entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('apigee_edge_actions.edge_entity_type_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getEntityTypes() : array {
    return $this->edgeEntityTypeManager
      ->getEntityTypes();
  }

  /**
   * {@inheritdoc}
   */
  public function getContext(EdgeEntityTypeInterface $entity_type) : array {
    $context = [
      $entity_type
        ->id() => [
        'type' => "entity:{$entity_type->id()}",
        'label' => $entity_type
          ->getLabel(),
      ],
    ];

    // Add additional context for App.
    if ($entity_type
      ->entityClassImplements(AppInterface::class)) {

      // Add the developer to the context.
      $context['developer'] = [
        'type' => 'entity:user',
        'label' => 'Developer',
      ];

      // Add the team to the context.
      if ($entity_type
        ->entityClassImplements(TeamAppInterface::class)) {
        $context['team'] = [
          'type' => 'entity:team',
          'label' => 'Team',
        ];
      }
    }
    return $context;
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this
      ->getEntityTypes() as $entity_type) {
      $this->derivatives[$entity_type
        ->id()] = [
        'label' => $this
          ->getLabel($entity_type),
        'category' => $entity_type
          ->getLabel(),
        'entity_type_id' => $entity_type
          ->id(),
        'context_definitions' => $this
          ->getContext($entity_type),
      ] + $base_plugin_definition;
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
EdgeEntityEventDeriverBase::$edgeEntityTypeManager protected property The apigee app entity type manager service.
EdgeEntityEventDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EdgeEntityEventDeriverBase::getContext public function Returns an array of event context. Overrides EdgeEntityEventDeriverInterface::getContext 4
EdgeEntityEventDeriverBase::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EdgeEntityEventDeriverBase::getEntityTypes public function Returns an array of entity types that are compatible to this event. Overrides EdgeEntityEventDeriverInterface::getEntityTypes 3
EdgeEntityEventDeriverBase::__construct public function AppEventDeriver constructor.
EdgeEntityEventDeriverInterface::getLabel public function Returns the event's label. Example: 'After saving a new App'. 7
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.