public function ApigeeAuthKeyInput::processSubmittedKeyValue in Apigee Edge 8
Process a submitted key value.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The submitted value (with index "submitted") and the processed value (with index "processed_submitted").
Overrides KeyInputBase::processSubmittedKeyValue
File
- src/
Plugin/ KeyInput/ ApigeeAuthKeyInput.php, line 269
Class
- ApigeeAuthKeyInput
- Apigee Edge authentication credentials input text fields.
Namespace
Drupal\apigee_edge\Plugin\KeyInputCode
public function processSubmittedKeyValue(FormStateInterface $form_state) {
// Get input values.
$input_values = $form_state
->getValues();
if (!empty($input_values)) {
$instance_type = $input_values['instance_type'] ?? NULL;
// Make sure the endpoint defaults are not overridden by other values.
if ($instance_type == EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC) {
$input_values['endpoint'] = '';
}
if (empty($input_values['authorization_server_type']) || $input_values['authorization_server_type'] == 'default') {
$input_values['authorization_server'] = '';
}
// Remove unneeded values if on a Hybrid instance.
if ($instance_type == EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
$input_values['auth_type'] = '';
$input_values['username'] = '';
$input_values['password'] = '';
$input_values['endpoint'] = '';
$input_values['authorization_server_type'] = '';
$input_values['authorization_server'] = '';
$input_values['client_id'] = '';
$input_values['client_secret'] = '';
if (!empty($input_values['gcp_hosted'])) {
$input_values['account_json_key'] = '';
}
}
else {
// Remove unneeded values if on a Public or Private instance.
$input_values['account_json_key'] = '';
if (!empty($input_values['gcp_hosted'])) {
unset($input_values['gcp_hosted']);
}
// If password field is empty we just skip it and preserve the initial
// password if there is one already.
if (empty($input_values['password']) && !empty($form_state
->get('key_value')['current'])) {
$values = $this
->getFormDefaultValues($form_state);
if (!empty($values['password'])) {
$input_values['password'] = $values['password'];
}
}
}
// Remove `key_value` so it doesn't get double encoded.
unset($input_values['key_value']);
}
// Reset values to just `key_value`.
$form_state
->setValues([
'key_value' => Json::encode(array_filter($input_values)),
]);
return parent::processSubmittedKeyValue($form_state);
}