protected function AppCredentialEventSubscriber::dispatchRulesEvent in Apigee Edge 8
Helper to dispatch a corresponding rules event for an api credential event.
Parameters
string $rules_event_name: The name of the rules event.
\Symfony\Component\EventDispatcher\Event $event: The api credential event.
array $api_products: An array of api products.
2 calls to AppCredentialEventSubscriber::dispatchRulesEvent()
- AppCredentialEventSubscriber::onAddProduct in modules/
apigee_edge_actions/ src/ EventSubscriber/ AppCredentialEventSubscriber.php - Responds to add product events.
- AppCredentialEventSubscriber::onRemoveProduct in modules/
apigee_edge_actions/ src/ EventSubscriber/ AppCredentialEventSubscriber.php - Responds to remove product events.
File
- modules/
apigee_edge_actions/ src/ EventSubscriber/ AppCredentialEventSubscriber.php, line 129
Class
- AppCredentialEventSubscriber
- Events for an API Product being added to an app already exist.
Namespace
Drupal\apigee_edge_actions\EventSubscriberCode
protected function dispatchRulesEvent(string $rules_event_name, Event $event, array $api_products) {
try {
$app = $this
->getAppByName($event
->getAppName(), $event
->getOwnerId(), $event
->getAppType());
$app_type = "{$event->getAppType()}_app";
if ('developer_app' == $app_type) {
// For developer apps, get the Drupal account from the app owner.
/** @var \Drupal\apigee_edge\Entity\Storage\DeveloperStorageInterface $developer_storage */
/** @var \Drupal\apigee_edge\Entity\Developer $owner */
$developer_storage = $this->entityTypeManger
->getStorage($event
->getAppType());
$owner = $developer_storage
->load($event
->getOwnerId());
$developer = user_load_by_mail($owner
->getEmail());
}
else {
// For team apps, default to the current user.
$developer = $this->entityTypeManger
->getStorage('user')
->load($this->currentUser
->id());
}
foreach ($api_products as $product) {
/** @var \Drupal\apigee_edge\Entity\ApiProductInterface $api_product */
$api_product = $this->entityTypeManger
->getStorage('api_product')
->load($product);
$this->eventDispatcher
->dispatch($rules_event_name, new EdgeEntityEventEdge($app, [
$app_type => $app,
'developer' => $developer,
'api_product_name' => $api_product
->getName(),
'api_product_display_name' => $api_product
->getDisplayName(),
]));
}
} catch (PluginException $exception) {
$this->logger
->error($exception
->getMessage());
}
}