You are here

protected function ApigeeAuthKeyInput::getFormDefaultValues in Apigee Edge 8

Get authentication from values.

2 calls to ApigeeAuthKeyInput::getFormDefaultValues()
ApigeeAuthKeyInput::buildConfigurationForm in src/Plugin/KeyInput/ApigeeAuthKeyInput.php
Form constructor.
ApigeeAuthKeyInput::processSubmittedKeyValue in src/Plugin/KeyInput/ApigeeAuthKeyInput.php
Process a submitted key value.

File

src/Plugin/KeyInput/ApigeeAuthKeyInput.php, line 327

Class

ApigeeAuthKeyInput
Apigee Edge authentication credentials input text fields.

Namespace

Drupal\apigee_edge\Plugin\KeyInput

Code

protected function getFormDefaultValues(FormStateInterface $form_state) {

  // When AJAX rebuilds the the form (f.e.: the "Send request" button) the
  // submitted data is only available in $form_state->getUserInput() and not
  // in $form_state->getValues(). Key is not prepared to handle this out of
  // the box this is the reason why we have to manually process the user
  // input and retrieve the submitted values here.
  $key_value = $form_state
    ->get('key_value')['current'];

  // Either null or an empty string.
  if (empty($key_value)) {

    // When "Test connection" reloads the page they are not yet processed.
    // @see \Drupal\key\Form\KeyFormBase::createPluginFormState()
    $key_input_plugin_form_state = clone $form_state;
    $key_input_plugin_form_state
      ->setValues($form_state
      ->getUserInput()['key_input_settings']);

    // @see \Drupal\key\Form\KeyFormBase::validateForm()
    $key_input_processed_values = $form_state
      ->getFormObject()
      ->getEntity()
      ->getKeyInput()
      ->processSubmittedKeyValue($key_input_plugin_form_state);
    $key_value = $key_input_processed_values['processed_submitted'];
  }

  // Could be an empty array.
  $values = Json::decode($key_value);
  $values['authorization_server_type'] = empty($values['authorization_server']) ? 'default' : 'custom';
  return $values;
}