You are here

final class ApiProductEntityAccessCacheReset in Apigee Edge 8

Ensures that entity access cache gets cleared on API product entities.

Hierarchy

Expanded class hierarchy of ApiProductEntityAccessCacheReset

1 string reference to 'ApiProductEntityAccessCacheReset'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses ApiProductEntityAccessCacheReset
apigee_edge.event_subscriber.api_product_entity_access_cache_reset in ./apigee_edge.services.yml
Drupal\apigee_edge\EventSubscriber\ApiProductEntityAccessCacheReset

File

src/EventSubscriber/ApiProductEntityAccessCacheReset.php, line 35

Namespace

Drupal\apigee_edge\EventSubscriber
View source
final class ApiProductEntityAccessCacheReset implements EventSubscriberInterface {

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  private $entityTypeManager;

  /**
   * ApiProductEntityAccessCacheReset constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      // Reset API product access when a app credentials gets
      // updated because having an app with a product grants access
      // to the product.
      // @see _apigee_edge_user_has_an_app_with_product()
      AppCredentialCreateEvent::EVENT_NAME => 'clearApiProductCache',
      AppCredentialGenerateEvent::EVENT_NAME => 'clearApiProductCache',
      AppCredentialDeleteEvent::EVENT_NAME => 'clearApiProductCache',
      AppCredentialAddApiProductEvent::EVENT_NAME => 'clearApiProductCache',
      AppCredentialDeleteApiProductEvent::EVENT_NAME => 'clearApiProductCache',
    ];
  }

  /**
   * Clears API product entity access cache.
   *
   * @param \Symfony\Component\EventDispatcher\Event $event
   *   Event that triggered this subscriber.
   */
  public function clearApiProductCache(Event $event) : void {
    $this->entityTypeManager
      ->getAccessControlHandler('api_product')
      ->resetCache();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApiProductEntityAccessCacheReset::$entityTypeManager private property The entity type manager service.
ApiProductEntityAccessCacheReset::clearApiProductCache public function Clears API product entity access cache.
ApiProductEntityAccessCacheReset::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ApiProductEntityAccessCacheReset::__construct public function ApiProductEntityAccessCacheReset constructor.