diff --git a/src/Entity/BrightcoveAPIClient.php b/src/Entity/BrightcoveAPIClient.php index 7be5abe..8f8af83 100644 --- a/src/Entity/BrightcoveAPIClient.php +++ b/src/Entity/BrightcoveAPIClient.php @@ -29,6 +29,15 @@ use Brightcove\API\Client; * "label" = "label", * "uuid" = "uuid" * }, + * config_export={ + * "id" = "id", + * "label" = "label", + * "account_id" = "account_id", + * "client_id" = "client_id", + * "default_player" = "default_player", + * "secret_key" = "secret_key", + * "max_custom_fields" = "max_custom_fields", + * }, * links = { * "add-form" = "/admin/config/media/brightcove_api_client/add", * "edit-form" = "/admin/config/media/brightcove_api_client/{brightcove_api_client}", diff --git a/src/Form/BrightcoveAPIClientDeleteForm.php b/src/Form/BrightcoveAPIClientDeleteForm.php index e913c4a..5bbb9db 100644 --- a/src/Form/BrightcoveAPIClientDeleteForm.php +++ b/src/Form/BrightcoveAPIClientDeleteForm.php @@ -4,8 +4,10 @@ namespace Drupal\brightcove\Form; use Drupal\brightcove\BrightcoveUtil; use Drupal\brightcove\Entity\BrightcoveSubscription; +use Drupal\Core\Config\Entity\Query\QueryFactory; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Queue\QueueInterface; use Drupal\Core\Url; @@ -93,7 +95,7 @@ class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase { * Subscription delete queue object. */ public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $connection, QueueInterface $playlist_local_delete_queue, QueueInterface $video_local_delete_queue, QueueInterface $player_delete_queue, QueueInterface $custom_field_delete_queue, QueueInterface $text_track_delete_queue, QueueInterface $subscription_delete_queue) { - $this->entity_type_manager = $entity_type_manager; + $this->entityTypeManager = $entity_type_manager; $this->connection = $connection; $this->playlistLocalDeleteQueue = $playlist_local_delete_queue; $this->videoLocalDeleteQueue = $video_local_delete_queue; @@ -108,7 +110,7 @@ class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.query'), + $container->get('entity_type.manager'), $container->get('database'), $container->get('queue')->get('brightcove_playlist_local_delete_queue_worker'), $container->get('queue')->get('brightcove_video_local_delete_queue_worker'), @@ -160,9 +162,10 @@ class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase { } // Collect all playlists belonging for the api client. - $playlists = $this->entityTypeManager->get('brightcove_playlist') - ->condition('api_client', $entity->id()) - ->execute(); + $playlistQuery = $this->entityTypeManager->getStorage('brightcove_playlist')->getQuery(); + $playlistQuery->condition('api_client', $entity->id()); + $playlists = $playlistQuery->execute(); + foreach ($playlists as $playlist) { $this->playlistLocalDeleteQueue->createItem($playlist); } @@ -179,7 +182,7 @@ class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase { } // Collect all videos belonging for the api client. - $videos = $this->entityTypeManager->get('brightcove_video') + $videos = $this->entityTypeManager->getStorage('brightcove_video')->getQuery() ->condition('api_client', $entity->id()) ->execute(); foreach ($videos as $video) { @@ -187,7 +190,7 @@ class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase { } // Collect all players belonging for the api client. - $players = $this->entityTypeManager->get('brightcove_player') + $players = $this->entityTypeManager->getStorage('brightcove_player')->getQuery() ->condition('api_client', $entity->id()) ->execute(); foreach ($players as $player) { @@ -195,7 +198,7 @@ class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase { } // Collect all custom fields belonging for the api client. - $custom_fields = $this->entityTypeManager->get('brightcove_custom_field') + $custom_fields = $this->entityTypeManager->getStorage('brightcove_custom_field')->getQuery() ->condition('api_client', $entity->id()) ->execute(); foreach ($custom_fields as $custom_field) { diff --git a/src/Form/BrightcoveAPIClientForm.php b/src/Form/BrightcoveAPIClientForm.php index 45bfe75..83ae952 100644 --- a/src/Form/BrightcoveAPIClientForm.php +++ b/src/Form/BrightcoveAPIClientForm.php @@ -12,8 +12,12 @@ use Drupal\brightcove\Entity\BrightcoveAPIClient; use Drupal\brightcove\Entity\BrightcovePlayer; use Drupal\brightcove\Entity\BrightcoveSubscription; use Drupal\Core\Config\Config; +use Drupal\Core\Config\Entity\Query\QueryFactory; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; use Drupal\Core\Queue\QueueInterface; @@ -61,11 +65,11 @@ class BrightcoveAPIClientForm extends EntityForm { protected $subscriptionsQueue; /** - * Entity Type Manager. + * Brightcove API Client Query object. * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface + * @var \Drupal\Core\Entity\Query\QueryInterface */ - protected $entityTypeManager; + protected $apiClientQuery; /** * Key/Value expirable store. @@ -87,18 +91,20 @@ class BrightcoveAPIClientForm extends EntityForm { * Custom field queue. * @param \Drupal\Core\Queue\QueueInterface $subscriptions_queue * Custom field queue. - * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory + * @param \Drupal\Core\Entity\EntityTypeInterface $brightcove_api_client + * Brightcove API Client definition. + * @param \Drupal\Core\Config\Entity\Query\QueryFactory $config_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, EntityTypeManagerInterface $entity_type_manager, KeyValueStoreExpirableInterface $key_value_expirable_store) { + public function __construct(Config $config, EntityStorageInterface $player_storage, QueueInterface $player_queue, QueueInterface $custom_field_queue, QueueInterface $subscriptions_queue, EntityTypeInterface $brightcove_api_client, QueryFactory $config_query_factory, KeyValueStoreExpirableInterface $key_value_expirable_store) { $this->config = $config; $this->playerStorage = $player_storage; $this->playerQueue = $player_queue; $this->customFieldQueue = $custom_field_queue; $this->subscriptionsQueue = $subscriptions_queue; - $this->entityTypeManager = $entity_type_manager; + $this->apiClientQuery = $config_query_factory->get($brightcove_api_client, 'AND'); $this->keyValueExpirableStore = $key_value_expirable_store; } @@ -112,7 +118,8 @@ class BrightcoveAPIClientForm extends EntityForm { $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('entity_type.manager')->getDefinition('brightcove_api_client'), + $container->get('entity.query.config'), $container->get('keyvalue.expirable')->get('brightcove_access_token') ); } @@ -208,8 +215,7 @@ class BrightcoveAPIClientForm extends EntityForm { } // Count BrightcoveAPIClients. - $api_clients_number = $this->entityTypeManager->get('brightcove_api_client') - ->count()->execute(); + $api_clients_number = $this->apiClientQuery->count()->execute(); $form['default_client'] = [ '#type' => 'checkbox', '#title' => $this->t('Default API Client'),