Comments

Xiaohua Guan created an issue. See original summary.

xiaohua guan’s picture

Status: Active » Needs review
StatusFileSize
new3 KB
xiaohua guan’s picture

@yas

Please review the patch. Thanks.

Because there is no entity type VPC, I can't add a link to vpc_id.

yas’s picture

Status: Needs review » Needs work

@xiaohua-guan,

Could you please add the fieldset in the edit view as the same manner as the detailed view?

In detailed view,

  • Snapshot (Fieldset should be open)
    • Security Group Name
    • Description
    • VPC ID
  • Others (Fieldset should be closed)
    • Authored by

In edit view,

  • Snapshot (Fieldset should be open)
    • Name
    • Security Group Name
    • Description
    • VPC ID
  • Others (Fieldset should be closed)
    • Cloud ID
    • Authored by
xiaohua guan’s picture

StatusFileSize
new6.71 KB
xiaohua guan’s picture

StatusFileSize
new7.23 KB
xiaohua guan’s picture

@yas

Please review the new patch. Thanks.

xiaohua guan’s picture

Status: Needs work » Needs review
yas’s picture

Status: Needs review » Reviewed & tested by the community

@xiaohua-guan

I tested it, looks so nice. I'll merge the patch and mark this issue as Fixed.

  • yas committed 5f6031e on 8.x-1.x authored by Xiaohua Guan
    Issue #3025252 by Xiaohua Guan, yas: Use a link to a resource in...
yas’s picture

Status: Reviewed & tested by the community » Fixed
baldwinlouie’s picture

Priority: Normal » Major
Status: Fixed » Needs work
+++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/SecurityGroupEditForm.php
@@ -25,62 +24,71 @@ class SecurityGroupEditForm extends CloudContentForm {
-    $form['cloud_context'] = [
-      '#type'          => 'textfield',
-      '#title'         => $this->t('Cloud ID'),
-      '#maxlength'     => 255,
-      '#size'          => 60,
-      '#default_value' => !$entity->isNew()
-      ? $entity->getCloudContext()
-      : $cloud_context,
-      '#required'      => FALSE,
-      '#weight'        => -5,
-      '#attributes'    => ['readonly' => 'readonly'],
-      '#disabled'      => TRUE,
+    $weight = -50;
+
+    $form['security_group'] = [
+      '#type' => 'details',
+      '#title' => $this->t('Security Group'),
+      '#open' => TRUE,
+      '#weight' => $weight++,
     ];

Changing from #type=>textfield to #type=>item causes problem during the saving of the entity.

Form elements that are #type item are not saved back into the database. #type=>item is a display only form element.

So in the case of cloud_context, vpc_id, group_name, when saving them as #type=>item, Drupal will not be able to find those values, and save a NULL value into the database.

I found this behavior when working in issue https://www.drupal.org/project/cloud/issues/3023993. What ends up happening is that on a subsequent edit of the security group, all the plugins and api code will error out because cloud_context becomes NULL.

Steps to reproduce
1. Import security nodes
2. Edit one of them
3. Check the database. The cloud_context field will be null.

I think an alternative would to be make change the #type=>item fields to #type=>value. This will ensure Drupal has access to it. Then make a copy of the #type=>value into a new #type=>item for form display.

baldwinlouie’s picture

Status: Needs work » Closed (works as designed)

Please ignore my comment in #12. I found this function, copyFormItemValues(), which fixed the issue described above.