public function ApigeeAuthKeyType::validateKeyValue in Apigee Edge 8
Allows the Key Type plugin to validate the key value.
Parameters
array $form: An associative array containing the structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the plugin form.
string|null $key_value: The key value to be validated.
Overrides KeyTypeInterface::validateKeyValue
File
- src/
Plugin/ KeyType/ ApigeeAuthKeyType.php, line 106
Class
- ApigeeAuthKeyType
- Key type for Apigee Edge authentication credentials.
Namespace
Drupal\apigee_edge\Plugin\KeyTypeCode
public function validateKeyValue(array $form, FormStateInterface $form_state, $key_value) {
if (empty($key_value)) {
return;
}
$value = $this
->unserialize($key_value);
if ($value === NULL) {
$form_state
->setError($form, $this
->t('The key value does not contain valid JSON: @error', [
'@error' => json_last_error_msg(),
]));
return;
}
foreach ($this
->getPluginDefinition()['multivalue']['fields'] as $id => $field) {
if (isset($field['required']) && !$field['required']) {
continue;
}
$error_element = $form['settings']['input_section']['key_input_settings'][$id] ?? $form;
if (!isset($value[$id])) {
$form_state
->setError($error_element, $this
->t('The key value is missing the field %field.', [
'%field' => $field['label']
->render(),
]));
}
elseif (empty($value[$id])) {
$form_state
->setError($error_element, $this
->t('The key value field %field is empty.', [
'%field' => $field['label']
->render(),
]));
}
}
}