class AuthenticationForm in Apigee Edge 8
Provides a form for saving the Apigee Edge API authentication key.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\key\Form\KeyFormBase
- class \Drupal\key\Form\KeyEditForm
- class \Drupal\apigee_edge\Form\AuthenticationForm
- class \Drupal\key\Form\KeyEditForm
- class \Drupal\key\Form\KeyFormBase
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of AuthenticationForm
1 file declares its use of AuthenticationForm
- AuthenticationFormJsTest.php in tests/
src/ FunctionalJavascript/ Form/ AuthenticationFormJsTest.php
1 string reference to 'AuthenticationForm'
File
- src/
Form/ AuthenticationForm.php, line 35
Namespace
Drupal\apigee_edge\FormView source
class AuthenticationForm extends KeyEditForm {
/**
* The config name that stores the authentication key entity id.
*
* @var string
*/
public const CONFIG_NAME = 'apigee_edge.auth';
/**
* The default key entity id created by this form.
*
* @var string
*/
public const DEFAULT_KEY_ENTITY_ID = 'apigee_edge_connection_default';
/**
* AuthenticationForm constructor.
*
* @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $key_storage
* The key storage.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ConfigEntityStorageInterface $key_storage, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
parent::__construct($key_storage);
$this->configFactory = $config_factory;
// Module handler must be set but Key does not set it.
$this->moduleHandler = $module_handler;
// If we use `$this->config()`, config overrides won't be considered.
$config = $config_factory
->get(static::CONFIG_NAME);
// Loads to the key entity that belongs to the active key or creates a
// new one _without_ saving it.
if (!($active_key_id = $config
->get('active_key')) || !($active_key = $key_storage
->load($active_key_id))) {
/** @var \Drupal\key\KeyInterface $active_key */
$active_key = $key_storage
->create([
'id' => static::DEFAULT_KEY_ENTITY_ID,
'label' => $this
->t('Apigee Edge connection'),
'description' => $this
->t('Contains the credentials for connecting to Apigee Edge.'),
'key_type' => 'apigee_auth',
'key_input' => 'apigee_auth_input',
'key_provider' => 'apigee_edge_private_file',
]);
}
// Sets the entity object for the form. This is the best place where we
// can do that if we do not want to override n+1 methods inherited from the
// EntityForm.
$this->entity = $active_key;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage('key'), $container
->get('config.factory'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'apigee_edge_authentication_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Do the same trick as Key does in its add form.
// (Key should provide a "default" form that should be to handle
// both key add and edit operations just like Node does.
// Drupal\key\Form\KeyAddForm::buildForm()
// Only when the form is first built.
if ($this->entity
->isNew() && !$form_state
->isRebuilding()) {
// Set the key value data to NULL, since this is a new key.
$form_state
->set('key_value', [
'original' => NULL,
'processed_original' => NULL,
'obscured' => NULL,
'current' => '',
]);
}
// Hide the confirmation step added by Key.
if (!$this->editConfirmed) {
$this
->confirmEdit($form, $form_state);
$form_state
->setRebuild(FALSE);
}
$form = parent::buildForm($form, $form_state);
// Do not override title which is coming from the route.
unset($form['#title']);
// Hide fields that users should not be able to modify in this form.
$form['label']['#access'] = FALSE;
$form['id']['#access'] = FALSE;
$form['description']['#access'] = FALSE;
$form['settings']['type_section']['#access'] = FALSE;
$form['settings']['input_section']['#title'] = $this
->t('Apigee Edge connection settings');
$form['settings']['input_section']['#weight'] = 0;
$form['settings']['provider_section']['#title'] = $this
->t('Advanced settings');
// Provider selection should be closed by default unless the form rebuild
// trigger by the provider selector or there is an error with the
// key provider.
/** @var \Drupal\apigee_edge\Plugin\KeyProviderRequirementsInterface $key_provider */
$key_provider = $this->entity
->getKeyProvider();
$key_provider_requirements_error = FALSE;
// Warn user about key provider pre-requirement issues before form
// submission.
if ($key_provider instanceof KeyProviderRequirementsInterface) {
try {
$key_provider
->checkRequirements($this->entity);
} catch (KeyProviderRequirementsException $exception) {
$key_provider_requirements_error = TRUE;
$form['settings']['provider_section']['key_provider']['#attributes']['class'][] = 'error';
}
}
$form['settings']['provider_section']['#open'] = $key_provider_requirements_error || $form_state
->getTriggeringElement() && $form_state
->getTriggeringElement()['#name'] === 'key_provider';
$form['settings']['provider_section']['#weight'] = $form['settings']['input_section']['#weight'] + 1;
// Override the title of the submit button.
$form['actions']['submit']['#value'] = $this
->t('Save configuration');
// Hide the Delete button.
$form['actions']['delete']['#access'] = FALSE;
$form['#attached']['library'][] = 'apigee_edge/apigee_edge.admin';
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
// @see https://www.drupal.org/project/key/issues/3048562
$status = parent::save($form, $form_state);
// Save the authentication key entity id to module's configuration.
$this->configFactory
->getEditable(static::CONFIG_NAME)
->set('active_key', $this->entity
->id())
->save();
// Override the redirect destination.
$form_state
->setRedirect('apigee_edge.settings');
return $status;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthenticationForm:: |
public | function |
Form constructor. Overrides KeyEditForm:: |
|
AuthenticationForm:: |
public | constant | The config name that stores the authentication key entity id. | |
AuthenticationForm:: |
public static | function |
Instantiates a new instance of this class. Overrides KeyFormBase:: |
|
AuthenticationForm:: |
public | constant | The default key entity id created by this form. | |
AuthenticationForm:: |
public | function |
Returns a unique string identifying the form. Overrides EntityForm:: |
|
AuthenticationForm:: |
public | function |
Form submission handler for the 'save' action. Overrides KeyFormBase:: |
|
AuthenticationForm:: |
public | function |
AuthenticationForm constructor. Overrides KeyFormBase:: |
|
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 | |
EntityForm:: |
protected | property | The entity being used by this form. | 7 |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
private | property | The entity manager. | |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
2 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties | 7 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
5 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
1 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function | ||
EntityForm:: |
public | function | ||
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
KeyEditForm:: |
protected | property | Keeps track of extra confirmation step on key edit. | |
KeyEditForm:: |
public | function |
Returns an array of supported actions for the current entity form. Overrides EntityForm:: |
|
KeyEditForm:: |
public | function | Submit handler for the edit confirmation button. | |
KeyEditForm:: |
public | function |
Gets the actual form array to be built. Overrides KeyFormBase:: |
|
KeyEditForm:: |
public | function |
Form validation handler. Overrides KeyFormBase:: |
|
KeyFormBase:: |
protected | property | The original key. | |
KeyFormBase:: |
protected | property | The key storage. | |
KeyFormBase:: |
public | function | AJAX callback to update the dynamic settings on the form. | |
KeyFormBase:: |
protected | function | Creates a FormStateInterface object for a plugin. | |
KeyFormBase:: |
public | function | Returns the original key entity. | |
KeyFormBase:: |
protected | function | Moves form errors from one form state to another. | |
KeyFormBase:: |
protected | function | Moves storage variables from one form state to another. | |
KeyFormBase:: |
public | function |
This is the default entity object builder function. It is called before any
other submit handler to build the new entity object to be used by the
following submit handlers. At this point of the form workflow the entity is
validated and the form state… Overrides EntityForm:: |
|
KeyFormBase:: |
protected | function | Update the Key Input plugin. | |
KeyFormBase:: |
protected | function | Update the Key Provider plugin. | |
KeyFormBase:: |
protected | function | Update the Key Type plugin. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |