Skip to content
Snippets Groups Projects
Commit 74af88ff authored by Masami  Suzuki's avatar Masami Suzuki Committed by Yas Naoi
Browse files

Issue #3063512 by Masami, yas, Xiaohua Guan: Refactor the creation forms

parent 960729ac
No related branches found
No related tags found
No related merge requests found
Showing
with 130 additions and 50 deletions
......@@ -285,7 +285,7 @@ class AwsCloudContentForm extends CloudContentForm {
'#type' => 'details',
'#title' => $this->t('Others'),
'#open' => FALSE,
'#weight' => $weight,
'#weight' => $weight,
];
$form['others']['cloud_context'] = [
......@@ -305,6 +305,30 @@ class AwsCloudContentForm extends CloudContentForm {
'#disabled' => FALSE,
];
$form['others']['uid'] = $form['uid'];
unset($form['uid']);
}
/**
* Add the build array of fieldset others on create form.
*
* @param array $form
* The form array.
*/
protected function addOthersFieldsetCreateForm(array &$form) {
$form['others'] = [
'#type' => 'details',
'#title' => $this->t('Others'),
'#open' => FALSE,
'#weight' => $form['uid']['#weight'],
];
if (isset($form['langcode'])) {
$form['others']['langcode'] = $form['langcode'];
unset($form['langcode']);
}
$form['others']['uid'] = $form['uid'];
unset($form['uid']);
}
......
......@@ -22,7 +22,13 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$form['cloud_context'] = [
$form['elastic_IP'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Elastic IP'),
'#open' => TRUE,
];
$form['elastic_IP']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -35,7 +41,7 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['name'] = [
$form['elastic_IP']['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
......@@ -45,7 +51,7 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['domain'] = [
$form['elastic_IP']['domain'] = [
'#type' => 'select',
'#options' => [
'standard' => 'standard',
......@@ -57,7 +63,7 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
......@@ -22,7 +22,13 @@ class ImageCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$form['cloud_context'] = [
$form['image'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Image'),
'#open' => TRUE,
];
$form['image']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -35,7 +41,7 @@ class ImageCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['name'] = [
$form['image']['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
......@@ -45,7 +51,7 @@ class ImageCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['instance_id'] = [
$form['image']['instance_id'] = [
'#type' => 'textfield',
'#title' => $this->t('Instance ID'),
'#maxlength' => 60,
......@@ -55,7 +61,7 @@ class ImageCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['description'] = [
$form['image']['description'] = [
'#type' => 'textarea',
'#title' => $this->t('Description'),
'#maxlength' => 255,
......@@ -66,7 +72,7 @@ class ImageCreateForm extends AwsCloudContentForm {
'#required' => FALSE,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
......@@ -65,22 +65,28 @@ class ImageImportForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = '') {
$form['markup'] = [
$form['import_images'] = [
'#type' => 'details',
'#title' => $this->t('Images'),
'#open' => TRUE,
];
$form['import_images']['markup'] = [
'#markup' => $this->t('Use this form to import images into the system. Only one field is needed for searching. The import process can return a very large set of images. Please try to be specific in your search.'),
];
$form['owners'] = [
$form['import_images']['owners'] = [
'#type' => 'textfield',
'#title' => $this->t('Owners'),
'#description' => $this->t('Comma separated list of owners. For example "self, amazon". Specifying amazon will bring back around 4000 images, which is a rather large set of images.'),
];
$form['image_ids'] = [
$form['import_images']['image_ids'] = [
'#type' => 'textfield',
'#title' => $this->t('Image IDs'),
'#description' => $this->t('Comma separated list of image ids'),
];
$form['name'] = [
$form['import_images']['name'] = [
'#type' => 'select',
'#title' => $this->t('Search for images by AMI name'),
];
......@@ -98,7 +104,7 @@ Example: Find the current Ubuntu Server 18.04 LTS AMI:<br/>
</div>
EOD;
$form['examples'] = [
$form['import_images']['examples'] = [
'#type' => 'item',
'#title' => $this->t('Examples of AMI name'),
'#markup' => $markup,
......
......@@ -23,7 +23,13 @@ class KeyPairCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$form['cloud_context'] = [
$form['key_pair'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Key Pair'),
'#open' => TRUE,
];
$form['key_pair']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -36,7 +42,7 @@ class KeyPairCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['key_pair_name'] = [
$form['key_pair']['key_pair_name'] = [
'#type' => 'textfield',
'#title' => $this->t('Key Pair Name'),
'#maxlength' => 255,
......@@ -53,7 +59,7 @@ class KeyPairCreateForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
......@@ -25,7 +25,13 @@ class KeyPairImportForm extends AwsCloudContentForm {
$entity = $this->entity;
$form['cloud_context'] = [
$form['key_pair'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Key Pair'),
'#open' => TRUE,
];
$form['key_pair']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -36,7 +42,7 @@ class KeyPairImportForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['key_pair_name'] = [
$form['key_pair']['key_pair_name'] = [
'#type' => 'textfield',
'#title' => $this->t('Key Pair Name'),
'#maxlength' => 255,
......@@ -46,7 +52,7 @@ class KeyPairImportForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['key_pair_public_key'] = [
$form['key_pair']['key_pair_public_key'] = [
'#type' => 'file',
'#title' => 'Public Key',
'#description' => t('Upload your public key'),
......@@ -60,7 +66,7 @@ class KeyPairImportForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
......@@ -23,7 +23,13 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$form['cloud_context'] = [
$form['network_interface'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Network Interface'),
'#open' => TRUE,
];
$form['network_interface']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -36,7 +42,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['name'] = [
$form['network_interface']['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
......@@ -46,7 +52,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['description'] = [
$form['network_interface']['description'] = [
'#type' => 'textarea',
'#title' => $this->t('Description'),
'#cols' => 60,
......@@ -56,7 +62,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#required' => FALSE,
];
$form['subnet_id'] = [
$form['network_interface']['subnet_id'] = [
'#type' => 'textfield',
'#title' => $this->t('Subnet'),
'#size' => 60,
......@@ -65,7 +71,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#required' => TRUE,
];
$form['primary_private_ip'] = [
$form['network_interface']['primary_private_ip'] = [
'#type' => 'textfield',
'#title' => $this->t('Primary Private IP'),
'#size' => 60,
......@@ -74,7 +80,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#required' => TRUE,
];
$form['secondary_private_ips'] = [
$form['network_interface']['secondary_private_ips'] = [
'#type' => 'textfield',
'#title' => $this->t('Secondary Private IPs (Comma (,) separated.)'),
'#size' => 60,
......@@ -83,7 +89,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#required' => TRUE,
];
$form['is_primary'] = [
$form['network_interface']['is_primary'] = [
'#type' => 'checkbox',
'#title' => $this->t('Primary or Not'),
'#size' => 60,
......@@ -91,7 +97,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['security_groups'] = [
$form['network_interface']['security_groups'] = [
'#type' => 'textfield',
'#title' => $this->t('Security Groups'),
'#size' => 60,
......@@ -107,7 +113,7 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
......@@ -24,7 +24,13 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$form['cloud_context'] = [
$form['security_group'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Security Group'),
'#open' => TRUE,
];
$form['security_group']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -37,7 +43,7 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['group_name'] = [
$form['security_group']['group_name'] = [
'#type' => 'textfield',
'#title' => $this->t('Security Group Name'),
'#size' => 60,
......@@ -49,7 +55,7 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
$vpcs = $this->awsEc2Service->getVpcs();
$vpcs[$entity->getVpcId()] = 'N/A';
ksort($vpcs);
$form['vpc_id'] = [
$form['security_group']['vpc_id'] = [
'#type' => 'select',
'#title' => $this->t('VPC CIDR (ID)'),
'#options' => $vpcs,
......@@ -58,7 +64,7 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
'#required' => FALSE,
];
$form['description'] = [
$form['security_group']['description'] = [
'#type' => 'textarea',
'#title' => $this->t('Description'),
'#cols' => 60,
......@@ -75,6 +81,8 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$this->addOthersFieldsetCreateForm($form);
// Unset these until and present them on the edit security group form.
unset($form['ip_permission']);
unset($form['outbound_permission']);
......
......@@ -21,7 +21,13 @@ class SnapshotCreateForm extends AwsCloudContentForm {
$this->awsEc2Service->setCloudContext($cloud_context);
$entity = $this->entity;
$form['cloud_context'] = [
$form['snapshot'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Snapshot'),
'#open' => TRUE,
];
$form['snapshot']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -34,7 +40,7 @@ class SnapshotCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['name'] = [
$form['snapshot']['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
......@@ -46,7 +52,7 @@ class SnapshotCreateForm extends AwsCloudContentForm {
$volume_id = $this->getRequest()->query->get('volume_id');
$form['volume_id'] = [
$form['snapshot']['volume_id'] = [
'#type' => 'select',
'#title' => $this->t('Volume ID'),
'#options' => $this->getVolumeOptions($cloud_context),
......@@ -55,7 +61,7 @@ class SnapshotCreateForm extends AwsCloudContentForm {
'#required' => TRUE,
];
$form['description'] = [
$form['snapshot']['description'] = [
'#type' => 'textarea',
'#title' => $this->t('Description'),
'#maxlength' => 255,
......@@ -73,7 +79,7 @@ class SnapshotCreateForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
......@@ -40,7 +40,13 @@ class VolumeCreateForm extends AwsCloudContentForm {
}
}
$form['cloud_context'] = [
$form['volume'] = [
'#type' => 'details',
'#title' => $this->t('AWS Cloud Volume'),
'#open' => TRUE,
];
$form['volume']['cloud_context'] = [
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
......@@ -51,7 +57,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#disabled' => TRUE,
];
$form['name'] = [
$form['volume']['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
......@@ -61,7 +67,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['snapshot_id'] = [
$form['volume']['snapshot_id'] = [
'#type' => 'select',
'#title' => $this->t('Snapshot ID'),
'#options' => $this->getSnapshotOptions($cloud_context),
......@@ -71,7 +77,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#empty_value' => '',
];
$form['volume_type'] = [
$form['volume']['volume_type'] = [
'#type' => 'select',
'#title' => $this->t('Volume Type'),
'#options' => [
......@@ -84,7 +90,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#weight' => -5,
];
$form['size'] = [
$form['volume']['size'] = [
'#type' => 'textfield',
'#title' => $this->t('Size (GiB)'),
'#size' => 60,
......@@ -93,7 +99,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#required' => FALSE,
];
$form['iops'] = [
$form['volume']['iops'] = [
'#type' => 'textfield',
'#title' => $this->t('IOPS'),
'#size' => 60,
......@@ -103,7 +109,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
];
$availability_zones = $this->awsEc2Service->getAvailabilityZones();
$form['availability_zone'] = [
$form['volume']['availability_zone'] = [
'#type' => 'select',
'#title' => $this->t('Availability Zone'),
'#options' => $availability_zones,
......@@ -113,7 +119,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#required' => TRUE,
];
$form['encrypted'] = [
$form['volume']['encrypted'] = [
'#type' => 'checkbox',
'#title' => $this->t('Encrypted'),
'#size' => 60,
......@@ -122,7 +128,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#required' => FALSE,
];
$form['kms_key_id'] = [
$form['volume']['kms_key_id'] = [
'#type' => 'textfield',
'#title' => $this->t('KMS Key ID'),
'#size' => 60,
......@@ -138,7 +144,7 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$this->addOthersFieldsetCreateForm($form);
return $form;
}
......
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