cloud-8.x-2.0-beta1/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpDeleteForm.php

modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpDeleteForm.php
<?php

namespace Drupal\aws_cloud\Form\Ec2;

use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a form for deleting a ElasticIp entity.
 *
 * @ingroup aws_cloud
 */
class ElasticIpDeleteForm extends AwsDeleteForm {

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /* @var \Drupal\aws_cloud\Entity\Ec2\ElasticIp $entity */
    $entity = $this->entity;
    $this->ec2Service->setCloudContext($entity->getCloudContext());

    $allocation_id = $entity->getAllocationId();
    $public_ip = $entity->getPublicIp();
    $params = [];
    if ($entity->getDomain() == 'standard' && !empty($public_ip)) {
      $params['PublicIp'] = $public_ip;
    }
    elseif ($entity->getDomain() == 'vpc' && !empty($allocation_id)) {
      $params['AllocationId'] = $allocation_id;
    }
    if (!empty($params) && $this->ec2Service->releaseAddress($params) != NULL
    ) {

      // Update instances after the Elastic IP is deleted.
      $this->ec2Service->updateInstances();

      $message = $this->t('The @type "@label" has been deleted.', [
        '@type' => $entity->getEntityType()->getLabel(),
        '@label' => $entity->label(),
      ]);

      $entity->delete();
      $this->messenger->addMessage($message);
    }
    else {
      $message = $this->t('The @type "@label" couldn\'t delete.', [
        '@type' => $entity->getEntityType()->getLabel(),
        '@label' => $entity->label(),
      ]);
      $this->messenger->addError($message);
    }

    $form_state->setRedirect('view.aws_cloud_elastic_ip.list', ['cloud_context' => $entity->getCloudContext()]);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc