EdgeEntityEventDeriverBase.php in Apigee Edge 8
File
modules/apigee_edge_actions/src/Plugin/RulesEvent/EdgeEntityEventDeriverBase.php
View source
<?php
namespace Drupal\apigee_edge_actions\Plugin\RulesEvent;
use Drupal\apigee_edge_actions\ApigeeActionsEntityTypeHelperInterface;
use Drupal\apigee_edge\Entity\AppInterface;
use Drupal\apigee_edge\Entity\EdgeEntityTypeInterface;
use Drupal\apigee_edge_teams\Entity\TeamAppInterface;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class EdgeEntityEventDeriverBase extends DeriverBase implements EdgeEntityEventDeriverInterface {
use StringTranslationTrait;
protected $edgeEntityTypeManager;
public function __construct(ApigeeActionsEntityTypeHelperInterface $edge_entity_type_manager) {
$this->edgeEntityTypeManager = $edge_entity_type_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('apigee_edge_actions.edge_entity_type_manager'));
}
public function getEntityTypes() : array {
return $this->edgeEntityTypeManager
->getEntityTypes();
}
public function getContext(EdgeEntityTypeInterface $entity_type) : array {
$context = [
$entity_type
->id() => [
'type' => "entity:{$entity_type->id()}",
'label' => $entity_type
->getLabel(),
],
];
if ($entity_type
->entityClassImplements(AppInterface::class)) {
$context['developer'] = [
'type' => 'entity:user',
'label' => 'Developer',
];
if ($entity_type
->entityClassImplements(TeamAppInterface::class)) {
$context['team'] = [
'type' => 'entity:team',
'label' => 'Team',
];
}
}
return $context;
}
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;
}
}