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

Issue #3050346 by Xiaohua Guan, yas, baldwinlouie: Refactor AwsCloudConfig form

parent 8ff6b482
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ cloud.design.menu: ...@@ -10,7 +10,7 @@ cloud.design.menu:
# Cloud config menu items definition # Cloud config menu items definition
entity.cloud_config.collection: entity.cloud_config.collection:
title: 'Cloud config list' title: 'Profile list'
route_name: entity.cloud_config.collection route_name: entity.cloud_config.collection
description: 'List Cloud config entities' description: 'List Cloud config entities'
parent: system.admin_structure parent: system.admin_structure
......
...@@ -614,6 +614,19 @@ function aws_cloud_update_8135() { ...@@ -614,6 +614,19 @@ function aws_cloud_update_8135() {
cloud_update_yml_definitions(['views.view.aws_elastic_ip.yml'], 'aws_cloud'); cloud_update_yml_definitions(['views.view.aws_elastic_ip.yml'], 'aws_cloud');
} }
/**
* Update field_account_id and field_access_key definitions.
*/
function aws_cloud_update_8136() {
cloud_update_yml_definitions(
[
'field.field.cloud_config.aws_ec2.field_account_id.yml',
'field.field.cloud_config.aws_ec2.field_access_key.yml',
],
'aws_cloud'
);
}
/** /**
* Helper function to add fields to the entity type. * Helper function to add fields to the entity type.
* *
......
...@@ -1217,13 +1217,14 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_alter(&$form, FormStateInt ...@@ -1217,13 +1217,14 @@ function aws_cloud_form_cloud_config_aws_ec2_add_form_alter(&$form, FormStateInt
// Add checkboxes to enable regions. // Add checkboxes to enable regions.
$aws_ec2_service = \Drupal::service('aws_cloud.ec2'); $aws_ec2_service = \Drupal::service('aws_cloud.ec2');
$regions = $aws_ec2_service->getRegions(); $regions = $aws_ec2_service->getRegions();
$form['regions']['regions'] = [ $form['profile']['common']['regions'] = [
'#title' => t('Regions'), '#title' => t('Regions'),
'#description' => t('Select regions for which cloud config will be created.'), '#description' => t('Select regions for which cloud config will be created.'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => $regions, '#options' => $regions,
'#default_value' => array_keys($regions), '#default_value' => array_keys($regions),
'#required' => TRUE, '#required' => TRUE,
'#weight' => $form['profile']['common']['field_account_id']['#weight'] + 1,
]; ];
} }
...@@ -1479,31 +1480,30 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState ...@@ -1479,31 +1480,30 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState
'title' => t('Cloud Provider'), 'title' => t('Cloud Provider'),
'open' => TRUE, 'open' => TRUE,
'fields' => [ 'fields' => [
'field_cloud_type',
'cloud_context', 'cloud_context',
'name', 'name',
'field_description', 'field_description',
'field_cloud_type',
],
],
[
'name' => 'regions',
'title' => t('Regions'),
'open' => FALSE,
'fields' => [
'field_region',
], ],
], ],
[ [
'name' => 'credentials', 'name' => 'profile',
'title' => t('Credentials'), 'title' => t('Profile'),
'open' => TRUE, 'open' => TRUE,
'fields' => [ 'fields' => [],
'field_account_id',
],
'subfieldsets' => [ 'subfieldsets' => [
[ [
'name' => 'access_credentials', 'name' => 'common',
'title' => t('Access Credentials'), 'title' => t('Common'),
'open' => TRUE,
'fields' => [
'field_account_id',
'field_region',
],
],
[
'name' => 'credentials',
'title' => t('Credentials'),
'open' => TRUE, 'open' => TRUE,
'fields' => [ 'fields' => [
'field_use_instance_credentials', 'field_use_instance_credentials',
...@@ -1528,16 +1528,6 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState ...@@ -1528,16 +1528,6 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState
'open' => FALSE, 'open' => FALSE,
'fields' => [ 'fields' => [
'field_api_version', 'field_api_version',
'field_api_endpoint_uri',
],
],
[
'name' => 'image_upload',
'title' => t('Image Upload'),
'open' => FALSE,
'fields' => [
'field_image_upload_url',
'field_x_509_certificate',
], ],
], ],
]; ];
...@@ -1547,16 +1537,10 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState ...@@ -1547,16 +1537,10 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState
'title' => t('Others'), 'title' => t('Others'),
'open' => FALSE, 'open' => FALSE,
'fields' => [ 'fields' => [
'revision_log_message',
'uid', 'uid',
], ],
]; ];
// Add new_revision.
if (!$form_state->getFormObject()->getEntity()->isNew()) {
array_unshift($others['fields'], 'new_revision');
}
$fieldset_defs[] = $others; $fieldset_defs[] = $others;
// Hide the instance credential field, if security sever url not available. // Hide the instance credential field, if security sever url not available.
...@@ -1564,6 +1548,12 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState ...@@ -1564,6 +1548,12 @@ function aws_cloud_form_cloud_config_aws_ec2_form_common_alter(&$form, FormState
$form['field_use_instance_credentials']['#access'] = FALSE; $form['field_use_instance_credentials']['#access'] = FALSE;
} }
$form['field_api_endpoint_uri']['#access'] = FALSE;
$form['field_image_upload_url']['#access'] = FALSE;
$form['field_x_509_certificate']['#access'] = FALSE;
$form['new_revision']['#access'] = FALSE;
$form['revision_log_message']['#access'] = FALSE;
$form['#attached']['library'][] = 'aws_cloud/aws_cloud_config'; $form['#attached']['library'][] = 'aws_cloud/aws_cloud_config';
aws_cloud_form_reorder($form, $fieldset_defs); aws_cloud_form_reorder($form, $fieldset_defs);
......
...@@ -8,7 +8,7 @@ id: cloud_config.aws_ec2.field_access_key ...@@ -8,7 +8,7 @@ id: cloud_config.aws_ec2.field_access_key
field_name: field_access_key field_name: field_access_key
entity_type: cloud_config entity_type: cloud_config
bundle: aws_ec2 bundle: aws_ec2
label: 'Access Key Id' label: 'Access Key ID'
description: '16-32 Characters, e.g. 12ABCDEFGHIJKVWXYZ89 . If <em>Assume Role</em> is selected, enter the access key of the child user.' description: '16-32 Characters, e.g. 12ABCDEFGHIJKVWXYZ89 . If <em>Assume Role</em> is selected, enter the access key of the child user.'
required: false required: false
translatable: false translatable: false
......
...@@ -8,7 +8,7 @@ id: cloud_config.aws_ec2.field_account_id ...@@ -8,7 +8,7 @@ id: cloud_config.aws_ec2.field_account_id
field_name: field_account_id field_name: field_account_id
entity_type: cloud_config entity_type: cloud_config
bundle: aws_ec2 bundle: aws_ec2
label: 'User Id' label: 'Account ID'
description: 'e.g. 123456789012 If <em>Assume Role</em> is selected, enter the user id of the account to assume.' description: 'e.g. 123456789012 If <em>Assume Role</em> is selected, enter the user id of the account to assume.'
required: true required: true
translatable: false translatable: false
......
...@@ -257,12 +257,9 @@ class AwsCloudConfigTest extends BrowserTestBase { ...@@ -257,12 +257,9 @@ class AwsCloudConfigTest extends BrowserTestBase {
'field_description[0][value]' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') . $this->random->string(64, TRUE), 'field_description[0][value]' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') . $this->random->string(64, TRUE),
'field_api_version[0][value]' => 'latest', 'field_api_version[0][value]' => 'latest',
'field_region' => "us-west-$num", 'field_region' => "us-west-$num",
'field_api_endpoint_uri' => "https://ec2.us-west-$num.amazonaws.com",
'field_secret_key[0][value]' => $this->random->name(20, TRUE), 'field_secret_key[0][value]' => $this->random->name(20, TRUE),
'field_access_key[0][value]' => $this->random->name(40, TRUE), 'field_access_key[0][value]' => $this->random->name(40, TRUE),
'field_account_id[0][value]' => $this->random->name(16, TRUE), 'field_account_id[0][value]' => $this->random->name(16, TRUE),
'field_image_upload_url' => "https://ec2.us-west-$num.amazonaws.com",
'field_x_509_certificate[0][value]' => $this->random->string(255, TRUE),
'regions[us-east-1]' => 'us-east-1', 'regions[us-east-1]' => 'us-east-1',
]; ];
......
...@@ -330,7 +330,7 @@ class CloudConfig extends RevisionableContentEntityBase implements CloudConfigIn ...@@ -330,7 +330,7 @@ class CloudConfig extends RevisionableContentEntityBase implements CloudConfigIn
->setRequired(TRUE); ->setRequired(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string') $fields['cloud_context'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Provider Machine Name')) ->setLabel(t('Machine Name'))
->setRequired(TRUE) ->setRequired(TRUE)
->setDescription(t('A unique machine name for the cloud provider.')) ->setDescription(t('A unique machine name for the cloud provider.'))
->setRevisionable(TRUE); ->setRevisionable(TRUE);
......
...@@ -60,7 +60,7 @@ class CloudConfigForm extends ContentEntityForm { ...@@ -60,7 +60,7 @@ class CloudConfigForm extends ContentEntityForm {
$form['cloud_context'] = [ $form['cloud_context'] = [
'#type' => 'machine_name', '#type' => 'machine_name',
'#title' => $this->t('Cloud Provider Machine Name'), '#title' => $this->t('Machine Name'),
'#description' => $this->t('A unique machine name for the cloud provider.'), '#description' => $this->t('A unique machine name for the cloud provider.'),
'#default_value' => $this->entity->getCloudContext(), '#default_value' => $this->entity->getCloudContext(),
'#disabled' => !$this->entity->isNew(), '#disabled' => !$this->entity->isNew(),
......
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