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

Issue #3053608 by Xiaohua Guan, yas: For a region, there should be just one...

Issue #3053608 by Xiaohua Guan, yas: For a region, there should be just one AwsCloudConfig entity with the same AWS Account ID
parent bb84aecc
No related branches found
No related tags found
No related merge requests found
...@@ -1828,17 +1828,17 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_validate(array &$form, For ...@@ -1828,17 +1828,17 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_validate(array &$form, For
// Validate Name. // Validate Name.
$name = $form_state->getValue('name')[0]['value']; $name = $form_state->getValue('name')[0]['value'];
$aws_ec2_service = \Drupal::service('aws_cloud.ec2'); $aws_ec2_service = \Drupal::service('aws_cloud.ec2');
$regions = $aws_ec2_service->getRegions(); $regions_selected = array_values(array_filter($form_state->getValue('regions')));
$cloud_contexts = array_map(function ($region_name) use ($name) { $cloud_contexts_selected = array_map(function ($region_name) use ($name) {
return aws_cloud_form_cloud_config_aws_ec2_add_form_create_cloud_context($name, $region_name); return aws_cloud_form_cloud_config_aws_ec2_add_form_create_cloud_context($name, $region_name);
}, array_keys($regions)); }, array_keys($regions_selected));
$entities = \Drupal::service('plugin.manager.cloud_config_plugin')->loadConfigEntities('aws_ec2'); $entities = \Drupal::service('plugin.manager.cloud_config_plugin')->loadConfigEntities('aws_ec2');
$cloud_contexts_exist = array_map(function ($entity) { $cloud_contexts_exist = array_map(function ($entity) {
return $entity->getCloudContext(); return $entity->getCloudContext();
}, $entities); }, $entities);
if (!empty(array_intersect($cloud_contexts, $cloud_contexts_exist))) { if (!empty(array_intersect($cloud_contexts_selected, $cloud_contexts_exist))) {
$form_state->setErrorByName( $form_state->setErrorByName(
'name', 'name',
t('The cloud config entities with the same cloud context have existed.') t('The cloud config entities with the same cloud context have existed.')
...@@ -1847,7 +1847,6 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_validate(array &$form, For ...@@ -1847,7 +1847,6 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_validate(array &$form, For
// Validate Regions. // Validate Regions.
$account_id = $form_state->getValue('field_account_id')[0]['value']; $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) { $regions_used = array_map(function ($entity) use ($account_id) {
if ($entity->get('field_account_id')->value != $account_id) { if ($entity->get('field_account_id')->value != $account_id) {
return NULL; return NULL;
......
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