Skip to content
Snippets Groups Projects
Commit 4a9d7540 authored by Yas Naoi's avatar Yas Naoi Committed by Yas Naoi
Browse files

Issue #3068596 by yas, Xiaohua Guan, baldwinlouie: Refactor Cloud ID (Cloud...

Issue #3068596 by yas, Xiaohua Guan, baldwinlouie: Refactor Cloud ID (Cloud Context) in create / edit forms
parent e69d2c8f
No related branches found
No related tags found
No related merge requests found
Showing
with 62 additions and 185 deletions
......@@ -289,11 +289,15 @@ class AwsCloudContentForm extends CloudContentForm {
* @param array &$form
* The form array.
* @param int $weight
* The weight of the fieldset.
* The weight of the fieldset. The parameter's default value is 1
* to put the "Others" fieldset in between the main items and button(s)
* (e.g. "Save") if the parameter is omitted since 0 is the default value
* of the #weight attribute.
* @param string $cloud_context
* The cloud context.
*/
protected function addOthersFieldset(array &$form, $weight, $cloud_context = '') {
protected function addOthersFieldset(array &$form, $weight = 1, $cloud_context = '') {
$form['others'] = [
'#type' => 'details',
'#title' => $this->t('Others'),
......@@ -302,11 +306,15 @@ class AwsCloudContentForm extends CloudContentForm {
];
$form['others']['cloud_context'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Cloud ID')),
'#markup' => !$this->entity->isNew()
'#type' => 'textfield',
'#title' => $this->t('Cloud ID'),
'#maxlength' => 255,
'#size' => 60,
'#default_value' => !$this->entity->isNew()
? $this->entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#disabled' => TRUE,
];
$form['others']['langcode'] = [
......@@ -323,31 +331,6 @@ class AwsCloudContentForm extends CloudContentForm {
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'],
];
$form['others']['langcode'] = [
'#title' => t('Language'),
'#type' => 'language_select',
'#default_value' => $this->entity->getUntranslated()->language()->getId(),
'#languages' => Language::STATE_ALL,
];
$form['others']['uid'] = $form['uid'];
unset($form['uid']);
}
/**
* Helper function to get title translatable string of a item.
*
......
......@@ -22,23 +22,13 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew()
? $entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['elastic_IP']['name'] = [
......@@ -48,7 +38,6 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->label(),
'#required' => TRUE,
'#weight' => -5,
];
$form['elastic_IP']['domain'] = [
......@@ -60,10 +49,9 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
'#title' => $this->t('Domain (standard | vpc)'),
'#default_value' => 'standard',
'#required' => TRUE,
'#weight' => -5,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -96,7 +96,7 @@ class ElasticIpEditForm extends AwsCloudContentForm {
'#markup' => $entity->getNetworkInterfaceOwner(),
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$association_id = $this->entity->getAssociationId();
......
......@@ -22,23 +22,13 @@ class ImageCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew()
? $entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['image']['name'] = [
......@@ -48,7 +38,6 @@ class ImageCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->label(),
'#required' => FALSE,
'#weight' => -5,
];
$form['image']['instance_id'] = [
......@@ -58,7 +47,6 @@ class ImageCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->getInstanceId(),
'#required' => TRUE,
'#weight' => -5,
];
$form['image']['description'] = [
......@@ -68,11 +56,10 @@ class ImageCreateForm extends AwsCloudContentForm {
'#cols' => 60,
'#rows' => 3,
'#default_value' => $entity->getDescription(),
'#weight' => -5,
'#required' => FALSE,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -165,7 +165,7 @@ class ImageEditForm extends AwsCloudContentForm {
'#markup' => $entity->getBlockDevices(),
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
// Customize others fieldset.
$old_others = $form['others'];
......@@ -176,6 +176,7 @@ class ImageEditForm extends AwsCloudContentForm {
'#title' => $this->getItemTitle($this->t('Visibility')),
'#markup' => $entity->getVisibility(),
];
$form['others']['langcode'] = $old_others['langcode'];
$form['others']['uid'] = $old_others['uid'];
......
......@@ -330,7 +330,6 @@ class InstanceEditForm extends AwsCloudContentForm {
'#type' => 'checkbox',
'#description' => t('Indicates whether termination protection is enabled. If enabled, this instance cannot be terminated using the console, API, or CLI until termination protection is disabled.'),
'#default_value' => $entity->getTerminationProtection(),
'#weight' => $weight++,
];
$form['options']['is_monitoring'] = [
......@@ -338,21 +337,18 @@ class InstanceEditForm extends AwsCloudContentForm {
'#title' => $this->getItemTitle($this->t('Monitoring Enabled')),
'#markup' => $entity->isMonitoring()
? $this->t('Enabled') : $this->t('Disabled'),
'#weight' => $weight++,
];
$form['options']['ami_launch_index'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('AMI Launch Index')),
'#markup' => $entity->getAmiLaunchIndex(),
'#weight' => $weight++,
];
$form['options']['tenancy'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Tenancy')),
'#markup' => $entity->getTenancy(),
'#weight' => $weight++,
];
// Set a message for termination timestamp.
......@@ -374,14 +370,12 @@ class InstanceEditForm extends AwsCloudContentForm {
'#default_value' => isset($schedule) ? $entity->getSchedule() : '',
'#options' => aws_cloud_get_schedule(),
'#description' => t('Specify a start/stop schedule. This helps reduce server hosting costs.'),
'#weight' => $weight++,
];
$form['options']['login_username'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Login Username')),
'#markup' => $entity->getLoginUsername() ?: 'ec2-user',
'#weight' => $weight++,
];
$description = '';
......@@ -400,6 +394,7 @@ class InstanceEditForm extends AwsCloudContentForm {
$disabled = TRUE;
}
$form['options']['user_data'] = [
'#type' => 'textarea',
'#title' => $this->t('User Data'),
......@@ -413,7 +408,7 @@ class InstanceEditForm extends AwsCloudContentForm {
'#weight' => $weight++,
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$form['actions']['#weight'] = $weight++;
......
......@@ -22,23 +22,13 @@ class KeyPairCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew()
? $entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['key_pair']['key_pair_name'] = [
......@@ -48,10 +38,9 @@ class KeyPairCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->getKeyPairName(),
'#required' => TRUE,
'#weight' => -5,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -41,7 +41,7 @@ class KeyPairEditForm extends AwsCloudContentForm {
'#markup' => $entity->getKeyFingerprint(),
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
......
......@@ -25,21 +25,13 @@ class KeyPairImportForm extends AwsCloudContentForm {
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew() ? $entity->getCloudContext() : $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['key_pair']['key_pair_name'] = [
......@@ -49,7 +41,6 @@ class KeyPairImportForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->getKeyPairName(),
'#required' => TRUE,
'#weight' => -5,
];
$form['key_pair']['key_pair_public_key'] = [
......@@ -66,7 +57,7 @@ class KeyPairImportForm extends AwsCloudContentForm {
'#languages' => Language::STATE_ALL,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -22,23 +22,13 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew()
? $entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['network_interface']['name'] = [
......@@ -48,7 +38,6 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->label(),
'#required' => TRUE,
'#weight' => -5,
];
$form['network_interface']['description'] = [
......@@ -57,7 +46,6 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#cols' => 60,
'#rows' => 3,
'#default_value' => $entity->getDescription(),
'#weight' => -5,
'#required' => FALSE,
];
......@@ -69,7 +57,6 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'callback' => '::subnetAjaxCallback',
'wrapper' => 'security-groups-wrapper',
],
'#weight' => -5,
'#required' => TRUE,
];
......@@ -86,11 +73,10 @@ class NetworkInterfaceCreateForm extends AwsCloudContentForm {
'#size' => 5,
'#multiple' => TRUE,
'#options' => $this->getSecurityGroupOptions($cloud_context),
'#weight' => -5,
'#required' => TRUE,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -182,7 +182,7 @@ class NetworkInterfaceEditForm extends AwsCloudContentForm {
'#markup' => $entity->getAccountId(),
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
......
......@@ -23,23 +23,13 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew()
? $entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['security_group']['group_name'] = [
......@@ -47,7 +37,6 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
'#title' => $this->t('Security Group Name'),
'#size' => 60,
'#default_value' => $entity->getGroupName(),
'#weight' => -5,
'#required' => TRUE,
];
......@@ -59,7 +48,6 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
'#title' => $this->t('VPC CIDR (ID)'),
'#options' => $vpcs,
'#default_value' => $entity->getVpcId(),
'#weight' => -5,
'#required' => FALSE,
];
......@@ -69,18 +57,17 @@ class SecurityGroupCreateForm extends AwsCloudContentForm {
'#cols' => 60,
'#rows' => 3,
'#default_value' => $entity->getDescription(),
'#weight' => -5,
'#required' => TRUE,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
// Unset these until and present them on the edit security group form.
unset($form['ip_permission']);
unset($form['outbound_permission']);
if (isset($form['actions'])) {
$form['actions']['submit']['#weight'] = 1;
$form['actions']['submit']['#weight'] = $weight++;
}
return $form;
......
......@@ -85,7 +85,7 @@ class SecurityGroupEditForm extends AwsCloudContentForm {
unset($form['ip_permission']);
unset($form['outbound_permission']);
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['#attached']['library'][] = 'aws_cloud/aws_cloud_security_groups';
......
......@@ -20,23 +20,13 @@ class SnapshotCreateForm extends AwsCloudContentForm {
$this->awsEc2Service->setCloudContext($cloud_context);
$entity = $this->entity;
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew()
? $entity->getCloudContext()
: $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['snapshot']['name'] = [
......@@ -46,7 +36,6 @@ class SnapshotCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->label(),
'#required' => FALSE,
'#weight' => -5,
];
$volume_id = $this->getRequest()->query->get('volume_id');
......@@ -56,7 +45,6 @@ class SnapshotCreateForm extends AwsCloudContentForm {
'#title' => $this->t('Volume ID'),
'#options' => $this->getVolumeOptions($cloud_context),
'#default_value' => $volume_id,
'#weight' => -5,
'#required' => TRUE,
];
......@@ -67,11 +55,10 @@ class SnapshotCreateForm extends AwsCloudContentForm {
'#cols' => 60,
'#rows' => 3,
'#default_value' => $entity->getDescription(),
'#weight' => -5,
'#required' => FALSE,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -92,7 +92,7 @@ class SnapshotEditForm extends AwsCloudContentForm {
'#markup' => $this->dateFormatter->format($entity->created(), 'short'),
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$form['actions']['#weight'] = $weight++;
......
......@@ -39,21 +39,13 @@ class VolumeCreateForm extends AwsCloudContentForm {
}
}
$weight = -50;
$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,
'#size' => 60,
'#default_value' => !$entity->isNew() ? $entity->getCloudContext() : $cloud_context,
'#required' => TRUE,
'#weight' => -5,
'#disabled' => TRUE,
'#weight' => $weight++,
];
$form['volume']['name'] = [
......@@ -63,7 +55,6 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#size' => 60,
'#default_value' => $entity->label(),
'#required' => TRUE,
'#weight' => -5,
];
$form['volume']['snapshot_id'] = [
......@@ -86,7 +77,6 @@ class VolumeCreateForm extends AwsCloudContentForm {
'sc1' => $this->t('Cold HDD (sc1)'),
'st1' => $this->t('Throughput Optimized HDD (st1)'),
],
'#weight' => -5,
];
$form['volume']['size'] = [
......@@ -94,7 +84,6 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#title' => $this->t('Size (GiB)'),
'#size' => 60,
'#default_value' => $snapshot ? $snapshot->getSize() : '',
'#weight' => -5,
'#required' => FALSE,
];
......@@ -103,7 +92,6 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#title' => $this->t('IOPS'),
'#size' => 60,
'#default_value' => $entity->getIops(),
'#weight' => -5,
'#required' => FALSE,
];
......@@ -114,7 +102,6 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#options' => $availability_zones,
// Pick up the first availability zone in the array.
'#default_value' => array_shift($availability_zones),
'#weight' => -5,
'#required' => TRUE,
];
......@@ -123,7 +110,6 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#title' => $this->t('Encrypted'),
'#size' => 60,
'#default_value' => $entity->getEncrypted(),
'#weight' => -5,
'#required' => FALSE,
];
......@@ -133,11 +119,10 @@ class VolumeCreateForm extends AwsCloudContentForm {
'#title' => $this->t('KMS Key ID'),
'#size' => 60,
'#default_value' => $entity->getKmsKeyId(),
'#weight' => -5,
'#required' => FALSE,
];
$this->addOthersFieldsetCreateForm($form);
$this->addOthersFieldset($form, $weight++, $cloud_context);
return $form;
}
......
......@@ -119,7 +119,7 @@ class VolumeEditForm extends AwsCloudContentForm {
'#markup' => $this->dateFormatter->format($entity->created(), 'short'),
];
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
......
......@@ -45,7 +45,6 @@ class SubnetCreateForm extends AwsCloudContentForm {
'#title' => $this->t('VPC CIDR (ID)'),
'#options' => $vpcs,
'#default_value' => $entity->getVpcId(),
'#weight' => -5,
'#required' => TRUE,
];
......@@ -58,10 +57,10 @@ class SubnetCreateForm extends AwsCloudContentForm {
'#required' => TRUE,
];
$this->addOthersFieldset($form, $weight++, $cloud_context);
unset($form['tags']);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
return $form;
......
......@@ -24,7 +24,7 @@ class SubnetEditForm extends AwsCloudContentForm {
$form['subnet'] = [
'#type' => 'details',
'#title' => $this->t('Vpc'),
'#title' => $this->t('VPC'),
'#open' => TRUE,
'#weight' => $weight++,
];
......@@ -66,7 +66,7 @@ class SubnetEditForm extends AwsCloudContentForm {
$form['fieldset_tags'][] = $form['tags'];
unset($form['tags']);
$this->addOthersFieldset($form, $weight++);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$form['actions']['#weight'] = $weight++;
......
......@@ -19,7 +19,6 @@ class VpcCreateForm extends AwsCloudContentForm {
/* @var $entity \Drupal\aws_cloud\Entity\Ec2\Snapshot */
$form = parent::buildForm($form, $form_state);
$this->awsEc2Service->setCloudContext($cloud_context);
$entity = $this->entity;
$weight = -50;
......@@ -69,12 +68,12 @@ class VpcCreateForm extends AwsCloudContentForm {
],
];
$this->addOthersFieldset($form, $weight++, $cloud_context);
unset($form['tags']);
unset($form['cidr_blocks']);
unset($form['ipv6_cidr_blocks']);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
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