Commit 10188c7c authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3290820 by Xiaohua Guan, yas: Refactor the source code based on Drupal...

Issue #3290820 by Xiaohua Guan, yas: Refactor the source code based on Drupal best practices (1) (Unused variable)
parent 3530e8c2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -586,6 +586,7 @@ class InstanceEditForm extends AwsCloudContentForm {
      '#default_value' => $is_user_data_binary ? $entity->getUserData() : $user_data_decoded,
      '#required'      => FALSE,
      '#weight'        => $weight++,
      '#disabled'      => $disabled,
    ];

    $form['options']['user_data_base64_encoded'] = [
+0 −1
Original line number Diff line number Diff line
@@ -410,7 +410,6 @@ class SecurityGroupEditForm extends AwsCloudContentForm {
      $group = [];
      // Use GroupID if non-default VPC or EC2-Classic.
      // For other permissions, use Group Name.
      $vpc_id = $this->entity->getVpcId();
      if (!empty($ip_permission->getGroupId())) {
        $group['GroupId'] = $ip_permission->getGroupId();
      }
+0 −35
Original line number Diff line number Diff line
@@ -33,12 +33,10 @@ class InternetGatewayDetachForm extends AwsDeleteForm {

    // Get module name.
    $module_name = $this->getModuleName($entity);
    $vpc = $this->getVpcName($entity->getVpcId(), $module_name, $entity->getCloudContext());

    $msg = '<h2>Internet gateway information:</h2>';

    $internet_gateway_id = $entity->getInternetGatewayId();
    $name = $entity->getName();
    $vpc_id = $entity->getVpcId();

    $internet_gateway_link = $this->entityLinkRenderer->renderViewElement(
@@ -157,37 +155,4 @@ class InternetGatewayDetachForm extends AwsDeleteForm {
    $this->clearCacheValues($entity->getCacheTags());
  }

  /**
   * Helper method to get VPC name from database.
   *
   * @param string $vpc_id
   *   The VPC ID.
   * @param string $module_name
   *   Module name.
   * @param string $cloud_context
   *   Cloud context.
   *
   * @return string
   *   The VPC name.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  private function getVpcName($vpc_id, $module_name, $cloud_context): string {
    $name = '';
    $vpcs = $this->entityTypeManager
      ->getStorage("{$module_name}_vpc")
      ->loadByProperties([
        'vpc_id' => $vpc_id,
        'cloud_context' => $cloud_context,
      ]);

    if (count($vpcs)) {
      /** @var \Drupal\aws_cloud\Entity\Vpc\Vpc $vpc */
      $vpc = array_shift($vpcs);
      $name = $vpc->getName();
    }
    return $name;
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ class VpcEditForm extends AwsCloudContentForm {
      $entity->save();

      // Update the VPC.
      $result = $this->ec2Service->updateVpcs([
      $this->ec2Service->updateVpcs([
        'VpcId' => $entity->getVpcId(),
      ], FALSE);

+0 −2
Original line number Diff line number Diff line
@@ -1345,7 +1345,6 @@ class Ec2BatchOperations {
      : NULL;

    $timestamp = time();
    $name = $ec2Service->getTagName($transit_gateway_route_table, $transit_gateway_route_table_id);
    $entity_id = \Drupal::service('cloud')->getEntityId($cloud_context, 'aws_cloud_transit_gateway_route', 'transit_gateway_route_table_id', $transit_gateway_route_table_id);
    $uid = $ec2Service->getUidTagValue($transit_gateway_route_table, 'aws_cloud_transit_gateway_route');

@@ -1473,7 +1472,6 @@ class Ec2BatchOperations {
    $zone_id = $availability_zone['ZoneId'] ?? NULL;

    $timestamp = time();
    $name = $ec2Service->getTagName($availability_zone, $zone_id);
    $entity_id = \Drupal::service('cloud')->getEntityId($cloud_context, 'aws_cloud_availability_zone', 'zone_id', $zone_id);
    $uid = $ec2Service->getUidTagValue($availability_zone, 'aws_cloud_availability_zone');

Loading