class BrightcoveAPIClient in Brightcove Video Connect 8
Same name and namespace in other branches
- 8.2 src/Entity/BrightcoveAPIClient.php \Drupal\brightcove\Entity\BrightcoveAPIClient
- 3.x src/Entity/BrightcoveAPIClient.php \Drupal\brightcove\Entity\BrightcoveAPIClient
Defines the Brightcove API Client entity.
Plugin annotation
@ConfigEntityType(
id = "brightcove_api_client",
label = @Translation("Brightcove API Client"),
handlers = {
"list_builder" = "Drupal\brightcove\BrightcoveAPIClientListBuilder",
"form" = {
"add" = "Drupal\brightcove\Form\BrightcoveAPIClientForm",
"edit" = "Drupal\brightcove\Form\BrightcoveAPIClientForm",
"delete" = "Drupal\brightcove\Form\BrightcoveAPIClientDeleteForm"
},
},
config_prefix = "brightcove_api_client",
admin_permission = "administer brightcove configuration",
entity_keys = {
"id" = "id",
"label" = "label",
"uuid" = "uuid"
},
links = {
"add-form" = "/admin/config/media/brightcove_api_client/add",
"edit-form" = "/admin/config/media/brightcove_api_client/{brightcove_api_client}",
"delete-form" = "/admin/config/media/brightcove_api_client/{brightcove_api_client}/delete",
"collection" = "/admin/config/media/brightcove_api_client"
}
)
Hierarchy
- class \Drupal\Core\Entity\EntityBase implements EntityInterface uses RefinableCacheableDependencyTrait, DependencySerializationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityBase implements ConfigEntityInterface uses SynchronizableEntityTrait, PluginDependencyTrait
- class \Drupal\brightcove\Entity\BrightcoveAPIClient implements BrightcoveAPIClientInterface
- class \Drupal\Core\Config\Entity\ConfigEntityBase implements ConfigEntityInterface uses SynchronizableEntityTrait, PluginDependencyTrait
Expanded class hierarchy of BrightcoveAPIClient
6 files declare their use of BrightcoveAPIClient
- brightcove.install in ./
brightcove.install - Brightcove install file.
- brightcove.module in ./
brightcove.module - Brightcove module.
- BrightcoveAPIClientForm.php in src/
Form/ BrightcoveAPIClientForm.php - BrightcoveSubscriptionController.php in src/
Controller/ BrightcoveSubscriptionController.php - BrightcoveSubscriptionForm.php in src/
Form/ BrightcoveSubscriptionForm.php
File
- src/
Entity/ BrightcoveAPIClient.php, line 40
Namespace
Drupal\brightcove\EntityView source
class BrightcoveAPIClient extends ConfigEntityBase implements BrightcoveAPIClientInterface {
/**
* The Brightcove API Client ID (Drupal-internal).
*
* @var string
*/
protected $id;
/**
* The Brightcove API Client label.
*
* @var string
*/
protected $label;
/**
* The Brightcove API Client account ID.
*
* @var string
*/
protected $account_id;
/**
* The Brightcove API Client ID.
*
* @var string
*/
protected $client_id;
/**
* The Brightcove API Client default player.
*
* @var string
*/
protected $default_player;
/**
* The Brightcove API Client secret key.
*
* @var string
*/
protected $secret_key;
/**
* The loaded API client.
*
* @var \Brightcove\API\Client
*/
protected $client;
/**
* Client connection status.
*
* @var int
*/
protected $client_status;
/**
* Client connection status message.
*
* If the connection status is OK, then it's an empty string.
*
* @var string
*/
protected $client_status_message;
/**
* Indicate if there was an re-authorization attempt or not.
*
* @var bool
*/
private $re_authorization_tried = FALSE;
/**
* Maximum number of Custom fields.
*
* @var array
*/
protected $max_custom_fields;
/**
* Expirable key/value store for the client.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $key_value_expirable_store;
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->label;
}
/**
* {@inheritdoc}
*/
public function getAccountId() {
return $this->account_id;
}
/**
* {@inheritdoc}
*/
public function getClientId() {
return $this->client_id;
}
/**
* {@inheritdoc}
*/
public function getDefaultPlayer() {
return $this->default_player;
}
/**
* {@inheritdoc}
*/
public function getSecretKey() {
return $this->secret_key;
}
/**
* {@inheritdoc}
*/
public function getClient() {
$this
->authorizeClient();
return $this->client;
}
/**
* {@inheritdoc}
*/
public function getClientStatus() {
return $this->client_status;
}
/**
* {@inheritdoc}
*/
public function getClientStatusMessage() {
return $this->client_status_message;
}
/**
* {@inheritdoc}
*/
public function getAccessToken() {
return $this->key_value_expirable_store
->get($this->client_id, NULL);
}
/**
* {@inheritdoc}
*/
public function getMaxCustomFields() {
return $this->max_custom_fields;
}
/**
* {@inheritdoc}
*/
public function setLabel($label) {
$this->label = $label;
return $this;
}
/**
* {@inheritdoc}
*/
public function setAccountId($account_id) {
$this->account_id = $account_id;
return $this;
}
/**
* {@inheritdoc}
*/
public function setClientId($client_id) {
$this->client_id = $client_id;
return $this;
}
/**
* {@inheritdoc}
*/
public function setDefaultPlayer($default_player) {
$this->default_player = $default_player;
return $this;
}
/**
* {@inheritdoc}
*/
public function setSecretKey($secret_key) {
$this->secret_key = $secret_key;
return $this;
}
/**
* Set Brightcove API client.
*
* @param \Brightcove\API\Client $client
* The initialized Brightcove API Client.
*
* @return $this
*/
public function setClient(Client $client) {
$this->client = $client;
return $this;
}
/**
* {@inheritdoc}
*/
public function setAccessToken($access_token, $expire) {
$this->key_value_expirable_store
->setWithExpire($this->client_id, $access_token, $expire);
return $this;
}
/**
* {@inheritdoc}
*/
public function setMaxCustomFields($max_custom_fields) {
$this->max_custom_fields = $max_custom_fields;
return $this;
}
/**
* {@inheritdoc}
*/
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
$this->key_value_expirable_store = \Drupal::keyValueExpirable('brightcove_access_token');
}
/**
* Authorize client with Brightcove API and store client on the entity.
*
* @return $this
*
* @throws \Brightcove\API\Exception\AuthenticationException|\Exception
* Re-throw any exception to be able to handle them nicely.
*/
public function authorizeClient() {
try {
// Use the got access token while it is not expired.
if ($this->key_value_expirable_store
->has($this->client_id)) {
// Create new client.
$this
->setClient(new Client($this
->getAccessToken()));
}
else {
$client = Client::authorize($this->client_id, $this->secret_key);
// Update access information. This will ensure that in the current
// session we will get the correct access data.
// Set token expire time in seconds and subtract the default php
// max_execution_time from it.
// We have to use the default php max_execution_time because if we
// would get the value from ini_get('max_execution_time'), then it
// could be larger than the Brightcove's expire date causing to always
// get a new access token.
$this
->setAccessToken($client
->getAccessToken(), intval($client
->getExpiresIn()) - 30);
// Create new client.
$this
->setClient(new Client($this
->getAccessToken()));
}
// Test account ID.
$cms = new CMS($this->client, $this->account_id);
$cms
->countVideos();
// If client authentication was successful store it's state on the
// entity.
$this->client_status = self::CLIENT_OK;
} catch (\Exception $e) {
if ($e instanceof APIException) {
// If we got an unauthorized error, try to re-authorize the client
// only once.
if ($e
->getCode() == 401 && !$this->re_authorization_tried) {
$this->re_authorization_tried = TRUE;
$this
->authorizeClient();
}
}
// Store an error status and message on the entity if there was an
// error.
$this->client_status = self::CLIENT_ERROR;
$this->client_status_message = $e
->getMessage();
// If we have already tried to re-authorize the client, throw the
// exception outside of this scope, to be able to catch this Exception
// for better error handling.
if ($e
->getCode() != 401 && !$this->re_authorization_tried || $e
->getCode() == 401 && $this->re_authorization_tried) {
watchdog_exception('brightcove', $e, $e
->getMessage());
throw $e;
}
}
return $this;
}
/**
* Loads API client by the Brightcove account ID.
*
* @param string $account_id
* Brightcove account ID.
*
* @return \Drupal\brightcove\Entity\BrightcoveAPIClient|null
* Loaded BrightcoveAPIClient entity or NULL if cannot be found.
*/
public static function loadByAccountId($account_id) {
$api_client_ids = \Drupal::entityQuery('brightcove_api_client')
->condition('account_id', $account_id)
->execute();
if (!empty($api_client_ids)) {
return self::load(reset($api_client_ids));
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BrightcoveAPIClient:: |
protected | property | The Brightcove API Client account ID. | |
BrightcoveAPIClient:: |
protected | property | The loaded API client. | |
BrightcoveAPIClient:: |
protected | property | The Brightcove API Client ID. | |
BrightcoveAPIClient:: |
protected | property | Client connection status. | |
BrightcoveAPIClient:: |
protected | property | Client connection status message. | |
BrightcoveAPIClient:: |
protected | property | The Brightcove API Client default player. | |
BrightcoveAPIClient:: |
protected | property | The Brightcove API Client ID (Drupal-internal). | |
BrightcoveAPIClient:: |
protected | property | Expirable key/value store for the client. | |
BrightcoveAPIClient:: |
protected | property | The Brightcove API Client label. | |
BrightcoveAPIClient:: |
protected | property | Maximum number of Custom fields. | |
BrightcoveAPIClient:: |
private | property | Indicate if there was an re-authorization attempt or not. | |
BrightcoveAPIClient:: |
protected | property | The Brightcove API Client secret key. | |
BrightcoveAPIClient:: |
public | function | Authorize client with Brightcove API and store client on the entity. | |
BrightcoveAPIClient:: |
public | function |
Returns access token. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the API Client account ID. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the loaded API client. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the API Client ID. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the connection status. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the connection status message. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the API Client default player. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the API Client label. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the maximum number of addable custom fields. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Returns the API Client secret key. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public static | function | Loads API client by the Brightcove account ID. | |
BrightcoveAPIClient:: |
public | function |
Sets access token. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Sets the API Client account ID. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function | Set Brightcove API client. | |
BrightcoveAPIClient:: |
public | function |
Sets the API Client ID. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Sets the API Client default player. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Sets the API Client label. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Sets the maximum addable custom fields number. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Sets the API Client secret key. Overrides BrightcoveAPIClientInterface:: |
|
BrightcoveAPIClient:: |
public | function |
Constructs an Entity object. Overrides ConfigEntityBase:: |
|
BrightcoveAPIClientInterface:: |
constant | Indicates that the connection to the API was not successful. | ||
BrightcoveAPIClientInterface:: |
constant | Indicates that the connection to the API was successful. | ||
BrightcoveAPIClientInterface:: |
constant | Indicates the default player for any API Client. | ||
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
ConfigEntityBase:: |
private | property | Whether the config is being deleted by the uninstall process. | |
ConfigEntityBase:: |
protected | property | The language code of the entity's default language. | |
ConfigEntityBase:: |
protected | property | The original ID of the configuration entity. | |
ConfigEntityBase:: |
protected | property | The enabled/disabled status of the configuration entity. | 4 |
ConfigEntityBase:: |
protected | property | Third party entity settings. | |
ConfigEntityBase:: |
protected | property | Trust supplied data and not use configuration schema on save. | |
ConfigEntityBase:: |
protected | property | The UUID for this entity. | |
ConfigEntityBase:: |
protected | property | Information maintained by Drupal core about configuration. | |
ConfigEntityBase:: |
protected | function | Overrides \Drupal\Core\Entity\DependencyTrait:addDependency(). | |
ConfigEntityBase:: |
public | function |
Calculates dependencies and stores them in the dependency property. Overrides ConfigEntityInterface:: |
13 |
ConfigEntityBase:: |
public | function |
Creates a duplicate of the entity. Overrides EntityBase:: |
1 |
ConfigEntityBase:: |
public | function |
Disables the configuration entity. Overrides ConfigEntityInterface:: |
1 |
ConfigEntityBase:: |
public | function |
Enables the configuration entity. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Returns the value of a property. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Returns the cache tags that should be used to invalidate caches. Overrides EntityBase:: |
1 |
ConfigEntityBase:: |
public | function |
Gets the configuration dependency name. Overrides EntityBase:: |
|
ConfigEntityBase:: |
protected static | function | Gets the configuration manager. | |
ConfigEntityBase:: |
public | function |
Gets the configuration target identifier for the entity. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Gets the configuration dependencies. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets the original ID. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
protected | function | Gets the typed config manager. | |
ConfigEntityBase:: |
public | function |
Gets whether on not the data is trusted. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
protected static | function |
Override to never invalidate the individual entities' cache tags; the
config system already invalidates them. Overrides EntityBase:: |
|
ConfigEntityBase:: |
protected | function |
Override to never invalidate the entity's cache tag; the config system
already invalidates it. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Checks whether this entity is installable. Overrides ConfigEntityInterface:: |
2 |
ConfigEntityBase:: |
public | function |
Overrides Entity::isNew(). Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Returns whether this entity is being changed during the uninstall process. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Deprecated way of generating a link to the entity. See toLink(). Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Informs the entity that entities it depends on will be deleted. Overrides ConfigEntityInterface:: |
7 |
ConfigEntityBase:: |
public static | function |
Acts on entities before they are deleted and before hooks are invoked. Overrides EntityBase:: |
8 |
ConfigEntityBase:: |
public | function |
Acts on an entity before the presave hook is invoked. Overrides EntityBase:: |
13 |
ConfigEntityBase:: |
public | function |
Saves an entity permanently. Overrides EntityBase:: |
1 |
ConfigEntityBase:: |
public | function |
Sets the value of a property. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Sets the original ID. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Sets the status of the configuration entity. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function | ||
ConfigEntityBase:: |
public static | function | Helper callback for uasort() to sort configuration entities by weight and label. | 6 |
ConfigEntityBase:: |
public | function |
Returns whether the configuration entity is enabled. Overrides ConfigEntityInterface:: |
4 |
ConfigEntityBase:: |
public | function |
Gets an array of all property values. Overrides EntityBase:: |
2 |
ConfigEntityBase:: |
public | function |
Gets the URL object for the entity. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Sets that the data should be trusted. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Unsets a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets the public URL for this entity. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Gets the URL object for the entity. Overrides EntityBase:: |
|
ConfigEntityBase:: |
public | function |
Overrides EntityBase:: |
4 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | Aliased as: traitSleep | 1 |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. Aliased as: addDependencyTrait | |
EntityBase:: |
protected | property | Boolean indicating whether the entity should be forced to be new. | |
EntityBase:: |
protected | property | The entity type. | |
EntityBase:: |
protected | property | A typed data object wrapping this entity. | |
EntityBase:: |
public | function |
Checks data value access. Overrides AccessibleInterface:: |
1 |
EntityBase:: |
public | function |
Gets the bundle of the entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
public static | function |
Constructs a new entity object, without permanently saving it. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Deletes an entity permanently. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Enforces an entity to be new. Overrides EntityInterface:: |
|
EntityBase:: |
protected | function | Gets the entity manager. | |
EntityBase:: |
protected | function | Gets the entity type bundle info service. | |
EntityBase:: |
protected | function | Gets the entity type manager. | |
EntityBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyTrait:: |
|
EntityBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyTrait:: |
|
EntityBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyTrait:: |
|
EntityBase:: |
public | function |
Gets the key that is used to store configuration dependencies. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the entity type definition. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the ID of the type of the entity. Overrides EntityInterface:: |
|
EntityBase:: |
protected | function | The list cache tags to invalidate for this entity. | |
EntityBase:: |
public | function |
Gets a typed data object for this entity object. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Indicates if a link template exists for a given key. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the identifier. Overrides EntityInterface:: |
11 |
EntityBase:: |
public | function |
Gets the label of the entity. Overrides EntityInterface:: |
6 |
EntityBase:: |
public | function |
Gets the language of the entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
protected | function | Gets the language manager. | |
EntityBase:: |
protected | function | Gets an array link templates. | 1 |
EntityBase:: |
public static | function |
Loads an entity. Overrides EntityInterface:: |
|
EntityBase:: |
public static | function |
Loads one or more entities. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Acts on a created entity before hooks are invoked. Overrides EntityInterface:: |
4 |
EntityBase:: |
public static | function |
Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface:: |
16 |
EntityBase:: |
public static | function |
Acts on loaded entities. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Acts on a saved entity before the insert or update hook is invoked. Overrides EntityInterface:: |
14 |
EntityBase:: |
public static | function |
Changes the values of an entity before it is created. Overrides EntityInterface:: |
5 |
EntityBase:: |
public | function |
Gets a list of entities referenced by this entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
public | function |
Generates the HTML for a link to this entity. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets a list of URI relationships supported by this entity. Overrides EntityInterface:: |
|
EntityBase:: |
protected | function | Gets an array of placeholders for this entity. | 2 |
EntityBase:: |
public | function |
Gets the entity UUID (Universally Unique Identifier). Overrides EntityInterface:: |
1 |
EntityBase:: |
protected | function | Gets the UUID generator. | |
PluginDependencyTrait:: |
protected | function | Calculates and adds dependencies of a specific plugin instance. | 1 |
PluginDependencyTrait:: |
protected | function | Calculates and returns dependencies of a specific plugin instance. | |
PluginDependencyTrait:: |
protected | function | Wraps the module handler. | 1 |
PluginDependencyTrait:: |
protected | function | Wraps the theme handler. | 1 |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
SynchronizableEntityTrait:: |
protected | property | Whether this entity is being created, updated or deleted through a synchronization process. | |
SynchronizableEntityTrait:: |
public | function | ||
SynchronizableEntityTrait:: |
public | function |