abstract class ClientAuthorizationPluginBase in Entity Share 8.3
Base class for Client authorization plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\entity_share_client\ClientAuthorization\ClientAuthorizationPluginBase implements ContainerFactoryPluginInterface, ClientAuthorizationInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ClientAuthorizationPluginBase
4 files declare their use of ClientAuthorizationPluginBase
- Anonymous.php in modules/
entity_share_client/ src/ Plugin/ ClientAuthorization/ Anonymous.php - BasicAuth.php in modules/
entity_share_client/ src/ Plugin/ ClientAuthorization/ BasicAuth.php - Header.php in modules/
entity_share_client/ src/ Plugin/ ClientAuthorization/ Header.php - Oauth.php in modules/
entity_share_client/ src/ Plugin/ ClientAuthorization/ Oauth.php
File
- modules/
entity_share_client/ src/ ClientAuthorization/ ClientAuthorizationPluginBase.php, line 20
Namespace
Drupal\entity_share_client\ClientAuthorizationView source
abstract class ClientAuthorizationPluginBase extends PluginBase implements ClientAuthorizationInterface, ContainerFactoryPluginInterface {
/**
* Injected key service.
*
* @var \Drupal\entity_share_client\Service\KeyProvider
*/
protected $keyService;
/**
* The key value store to use.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
protected $keyValueStore;
/**
* Injected UUID service.
*
* @var \Drupal\Component\Uuid\UuidInterface
*/
protected $uuid;
/**
* Injected HTTP client factory.
*
* @var \Drupal\Core\Http\ClientFactory
*/
protected $httpClientFactory;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, KeyProvider $keyProvider, KeyValueFactoryInterface $key_value_factory, UuidInterface $uuid, ClientFactory $clientFactory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->keyService = $keyProvider;
$this->keyValueStore = $key_value_factory
->get(ClientAuthorizationInterface::LOCAL_STORAGE_KEY_VALUE_COLLECTION);
$this->uuid = $uuid;
$this->httpClientFactory = $clientFactory;
$this
->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_share_client.key_provider'), $container
->get('keyvalue'), $container
->get('uuid'), $container
->get('http_client_factory'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'uuid' => $this->uuid
->generate(),
'data' => [],
];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
return $this;
}
/**
* {@inheritdoc}
*/
public function getCredentialProvider() {
$configuration = $this
->getConfiguration();
return $configuration['data']['credential_provider'] ?? NULL;
}
/**
* {@inheritdoc}
*/
public function getStorageKey() {
$configuration = $this
->getConfiguration();
return $configuration['data']['storage_key'] ?? NULL;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form + [
'credential_provider' => [
'#type' => 'hidden',
'#value' => 'entity_share',
],
'entity_share' => [
'#type' => 'fieldset',
'#title' => $this
->t('Stored locally'),
],
];
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
if (empty($values['credential_provider'])) {
$form_state
->setError($form['credential_provider'], 'A credential provider is required.');
}
else {
$provider = $values['credential_provider'];
foreach ($values[$provider] as $key => $value) {
if (empty($value)) {
$form_state
->setError($form[$provider][$key], 'All credential values are required.');
}
}
}
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$key = NULL;
$values = $form_state
->getValues();
$configuration = $this
->getConfiguration();
$provider = $values['credential_provider'];
$credentials = $values[$provider];
switch ($provider) {
case 'entity_share':
$this->keyValueStore
->set($configuration['uuid'], $credentials);
$key = $configuration['uuid'];
break;
case 'key':
$this->keyValueStore
->delete($configuration['uuid']);
$key = $credentials['id'];
break;
}
$configuration['data'] = [
'credential_provider' => $provider,
'storage_key' => $key,
];
$this
->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['label'];
}
/**
* Helper method to build the credential provider elements of the form.
*
* @param array $form
* The configuration form.
*/
protected function expandedProviderOptions(array &$form) {
$provider = $this
->getCredentialProvider();
// Provide selectors for the api key credential provider.
$form['credential_provider'] = [
'#type' => 'select',
'#title' => $this
->t('Credential provider'),
'#default_value' => empty($provider) ? 'entity_share' : $provider,
'#options' => [
'entity_share' => $this
->t('Local storage'),
'key' => $this
->t('Key module'),
],
'#attributes' => [
'data-states-selector' => 'provider',
],
'#weight' => -99,
];
$form['entity_share']['#states'] = [
'required' => [
':input[data-states-selector="provider"]' => [
'value' => 'entity_share',
],
],
'visible' => [
':input[data-states-selector="provider"]' => [
'value' => 'entity_share',
],
],
'enabled' => [
':input[data-states-selector="provider"]' => [
'value' => 'entity_share',
],
],
];
$key_id = $provider == 'key' ? $this
->getStorageKey() : '';
$form['key'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Managed by the Key module'),
'#states' => [
'required' => [
':input[data-states-selector="provider"]' => [
'value' => 'key',
],
],
'visible' => [
':input[data-states-selector="provider"]' => [
'value' => 'key',
],
],
'enabled' => [
':input[data-states-selector="provider"]' => [
'value' => 'key',
],
],
],
];
$form['key']['id'] = [
'#type' => 'key_select',
'#title' => $this
->t('Select a stored Key'),
'#default_value' => $key_id,
'#empty_option' => $this
->t('- Please select -'),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientAuthorizationInterface:: |
public | function | Returns true if the plugin method is supported. | 4 |
ClientAuthorizationInterface:: |
public | function | Prepares a guzzle client for http operations with the supported auth. | 4 |
ClientAuthorizationInterface:: |
public | function | Prepares a guzzle client for JSON operations with the supported auth. | 4 |
ClientAuthorizationInterface:: |
constant | The collection ID of for authorization config local storage. | ||
ClientAuthorizationPluginBase:: |
protected | property | Injected HTTP client factory. | |
ClientAuthorizationPluginBase:: |
protected | property | Injected key service. | |
ClientAuthorizationPluginBase:: |
protected | property | The key value store to use. | |
ClientAuthorizationPluginBase:: |
protected | property | Injected UUID service. | |
ClientAuthorizationPluginBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
4 |
ClientAuthorizationPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
ClientAuthorizationPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
ClientAuthorizationPluginBase:: |
protected | function | Helper method to build the credential provider elements of the form. | |
ClientAuthorizationPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Returns the plugin data if it is set, otherwise returns NULL. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Gets the plugin label. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Returns the plugin data if it is set, otherwise returns NULL. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
ClientAuthorizationPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
ClientAuthorizationPluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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 | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |