Skip to content
Snippets Groups Projects
Commit ed9e40e1 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3053608 by Xiaohua Guan, yas, baldwinlouie: For a region, there should...

Issue #3053608 by Xiaohua Guan, yas, baldwinlouie: For a region, there should be just one AwsCloudConfig entity with the same AWS Account ID
parent 8eb7930b
No related branches found
No related tags found
No related merge requests found
......@@ -1339,7 +1339,7 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_submit(array $form, FormSt
* The current state of the form.
*/
function aws_cloud_form_cloud_config_aws_ec2_add_form_validate(array &$form, FormStateInterface $form_state) {
// Get regions.
// Validate Name.
$name = $form_state->getValue('name')[0]['value'];
$aws_ec2_service = \Drupal::service('aws_cloud.ec2');
$regions = $aws_ec2_service->getRegions();
......@@ -1358,6 +1358,28 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_validate(array &$form, For
t('The cloud config entities with the same cloud context have existed.')
);
}
// Validate Regions.
$account_id = $form_state->getValue('field_account_id')[0]['value'];
$regions_selected = array_values(array_filter($form_state->getValue('regions')));
$regions_used = array_map(function ($entity) use ($account_id) {
if ($entity->get('field_account_id')->value != $account_id) {
return NULL;
}
return $entity->get('field_region')->value;
}, $entities);
$regions_used = array_filter($regions_used);
if (!empty($regions_invalid = array_intersect($regions_selected, $regions_used))) {
$form_state->setErrorByName(
'regions',
t(
'The regions selected %regions_invalid have been used. Please select other regions.',
['%regions_invalid' => implode(',', $regions_invalid)]
)
);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment