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

Issue #3295194 by Masami, yas: Change OpenStackFloatingIpDeleteForm to use...

Issue #3295194 by Masami, yas: Change OpenStackFloatingIpDeleteForm to use OpenStackOperationsService
parent b8abaac8
Branches
Tags
3 merge requests!1316Issue #3310263: Release 4.5.0,!1260Issue #3307397: Release 4.4.0,!1174Issue #3295194: Change OpenStackFloatingIpDeleteForm to use OpenStackOperationsService
......@@ -2,7 +2,6 @@
namespace Drupal\openstack\Form;
use Drupal\openstack\Service\Ec2\OpenStackService as OpenStackEc2Service;
use Drupal\aws_cloud\Form\Ec2\ElasticIpDeleteForm;
use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
......@@ -15,6 +14,7 @@ use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\openstack\Service\OpenStackOperationsServiceInterface;
use Drupal\openstack\Service\OpenStackServiceFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -32,6 +32,13 @@ class OpenStackFloatingIpDeleteForm extends ElasticIpDeleteForm {
*/
protected $openStackServiceFactory;
/**
* The OpenStack operations Service.
*
* @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface
*/
protected $openStackOperationsService;
/**
* OpenStackFloatingIpDeleteForm constructor.
*
......@@ -57,6 +64,8 @@ class OpenStackFloatingIpDeleteForm extends ElasticIpDeleteForm {
* The entity link render service.
* @param \Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud service provider plugin manager (CloudConfigPluginManager).
* @param \Drupal\openstack\Service\OpenStackOperationsServiceInterface $openstack_operations_service
* The OpenStack Operations service.
*/
public function __construct(OpenStackServiceFactoryInterface $openstack_service_factory,
Ec2ServiceInterface $ec2_service,
......@@ -68,7 +77,8 @@ class OpenStackFloatingIpDeleteForm extends ElasticIpDeleteForm {
CacheBackendInterface $cacheRender,
CachedDiscoveryClearerInterface $plugin_cache_clearer,
EntityLinkRendererInterface $entity_link_renderer,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
CloudConfigPluginManagerInterface $cloud_config_plugin_manager,
OpenStackOperationsServiceInterface $openstack_operations_service) {
parent::__construct(
$ec2_service,
......@@ -84,6 +94,7 @@ class OpenStackFloatingIpDeleteForm extends ElasticIpDeleteForm {
);
$this->openStackServiceFactory = $openstack_service_factory;
$this->openStackOperationsService = $openstack_operations_service;
}
/**
......@@ -107,7 +118,8 @@ class OpenStackFloatingIpDeleteForm extends ElasticIpDeleteForm {
$container->get('cache.render'),
$container->get('plugin.cache_clearer'),
$container->get('entity.link_renderer'),
$container->get('plugin.manager.cloud_config_plugin')
$container->get('plugin.manager.cloud_config_plugin'),
$container->get('openstack.operations')
);
}
......@@ -120,32 +132,7 @@ class OpenStackFloatingIpDeleteForm extends ElasticIpDeleteForm {
* The current form state.
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
// Switch OpenStack EC2 or REST service based on $entity->getCloudContext().
$entity = $this->entity;
$this->ec2Service = $this->openStackServiceFactory->get($entity->getCloudContext());
if ($this->ec2Service instanceof OpenStackEc2Service) {
parent::submitForm($form, $form_state);
return;
}
$params = ['FloatingIpId' => $entity->getFloatingIpId()];
if (!empty($entity)
&& !empty($params)
&& !empty($this->ec2Service->releaseAddress($params))) {
$entity->delete();
$this->messenger->addStatus($this->getDeletionMessage());
$this->logDeletionMessage();
$this->clearCacheValues($entity->getCacheTags());
}
else {
$this->processOperationErrorStatus($entity, 'deleted');
}
$form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]);
$this->openStackOperationsService->deleteOpenStackFloatingIp($this->entity, $form, $form_state);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment