commit ee591bb602aca868aa4e45e597750348d7c1b191 Author: Doug Green Date: Mon Aug 14 15:21:33 2017 -0400 #2743319-8: Integrate with the key module, if available diff --git a/src/Entity/BrightcoveAPIClient.php b/src/Entity/BrightcoveAPIClient.php index 4398329..3a03c91 100644 --- a/src/Entity/BrightcoveAPIClient.php +++ b/src/Entity/BrightcoveAPIClient.php @@ -5,7 +5,10 @@ namespace Drupal\brightcove\Entity; use Brightcove\API\CMS; use Brightcove\API\Exception\APIException; use Brightcove\API\Exception\AuthenticationException; +use Drupal\brightcove\Entity\BrightcoveSubscription; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Url; use Drupal\brightcove\BrightcoveAPIClientInterface; use Brightcove\API\Client; @@ -362,4 +365,23 @@ class BrightcoveAPIClient extends ConfigEntityBase implements BrightcoveAPIClien return $this; } + + /** + * {@inheritdoc} + */ + public function postCreate(EntityStorageInterface $storage) { + // Create new default subscription. + BrightcoveSubscription::create([ + 'id' => "default_{$this->id()}", + 'status' => FALSE, + 'default' => TRUE, + 'api_client_id' => $this->id(), + 'endpoint' => Url::fromRoute('brightcove_notification_callback', [], ['absolute' => TRUE])->toString(), + 'events' => ['video-change'], + ])->save(FALSE); + + // Get Subscriptions the first time when the API client is being saved. + \Drupal::queue('brightcove_subscriptions_queue_worker\'')->createItem($this->id()); + } + } diff --git a/src/Form/BrightcoveAPIClientForm.php b/src/Form/BrightcoveAPIClientForm.php index 806a3ea..cd92e79 100644 --- a/src/Form/BrightcoveAPIClientForm.php +++ b/src/Form/BrightcoveAPIClientForm.php @@ -6,7 +6,6 @@ use Brightcove\API\Exception\APIException; use Brightcove\API\PM; use Drupal\brightcove\BrightcoveUtil; use Drupal\brightcove\Entity\BrightcovePlayer; -use Drupal\brightcove\Entity\BrightcoveSubscription; use Drupal\Core\Config\Config; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Entity\EntityForm; @@ -14,7 +13,6 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; use Drupal\Core\Queue\QueueInterface; -use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\brightcove\Entity\BrightcoveAPIClient; use Brightcove\API\Exception\AuthenticationException; @@ -56,13 +54,6 @@ class BrightcoveAPIClientForm extends EntityForm { protected $custom_field_queue; /** - * The subscriptions queue object. - * - * @var \Drupal\Core\Queue\QueueInterface - */ - protected $subscriptions_queue; - - /** * Query factory. * * @var \Drupal\Core\Entity\Query\QueryFactory @@ -87,19 +78,16 @@ class BrightcoveAPIClientForm extends EntityForm { * Player queue. * @param \Drupal\Core\Queue\QueueInterface $custom_field_queue * Custom field queue. - * @param \Drupal\Core\Queue\QueueInterface $subscriptions_queue - * Custom field queue. * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory * Query factory. * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable_store * Key/Value expirable store for "brightcove_access_token". */ - public function __construct(Config $config, EntityStorageInterface $player_storage, QueueInterface $player_queue, QueueInterface $custom_field_queue, QueueInterface $subscriptions_queue, QueryFactory $query_factory, KeyValueStoreExpirableInterface $key_value_expirable_store) { + public function __construct(Config $config, EntityStorageInterface $player_storage, QueueInterface $player_queue, QueueInterface $custom_field_queue, QueryFactory $query_factory, KeyValueStoreExpirableInterface $key_value_expirable_store) { $this->config = $config; $this->player_storage = $player_storage; $this->player_queue = $player_queue; $this->custom_field_queue = $custom_field_queue; - $this->subscriptions_queue = $subscriptions_queue; $this->query_factory = $query_factory; $this->key_value_expirable_store = $key_value_expirable_store; } @@ -113,7 +101,6 @@ class BrightcoveAPIClientForm extends EntityForm { $container->get('entity_type.manager')->getStorage('brightcove_player'), $container->get('queue')->get('brightcove_player_queue_worker'), $container->get('queue')->get('brightcove_custom_field_queue_worker'), - $container->get('queue')->get('brightcove_subscriptions_queue_worker'), $container->get('entity.query'), $container->get('keyvalue.expirable')->get('brightcove_access_token') ); @@ -310,19 +297,6 @@ class BrightcoveAPIClientForm extends EntityForm { 'custom_field' => $custom_field, ]); } - - // Create new default subscription. - BrightcoveSubscription::create([ - 'id' => "default_{$this->entity->id()}", - 'status' => FALSE, - 'default' => TRUE, - 'api_client_id' => $this->entity->id(), - 'endpoint' => Url::fromRoute('brightcove_notification_callback', [], ['absolute' => TRUE])->toString(), - 'events' => ['video-change'], - ])->save(FALSE); - - // Get Subscriptions the first time when the API client is being saved. - $this->subscriptions_queue->createItem($this->entity->id()); } }