Skip to content
Snippets Groups Projects
Commit 7cb6aefc authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3036835 by baldwinlouie, yas, Xiaohua Guan: Update UI elements for Elastic IP

parent 3cbccfbc
No related branches found
No related tags found
No related merge requests found
Showing
with 304 additions and 222 deletions
......@@ -121,6 +121,20 @@ entity.aws_cloud_elastic_ip.collection:
- entity.aws_cloud_elastic_ip.edit_form
- entity.aws_cloud_elastic_ip.delete_form
entity.aws_cloud_elastic_ip.associate:
route_name: entity.aws_cloud_elastic_ip.associate_form
title: 'Associate Elastic Ip'
appears_on:
- entity.aws_cloud_elastic_ip.add_form
- entity.aws_cloud_elastic_ip.edit_form
entity.aws_cloud_elastic_ip.disassociate:
route_name: entity.aws_cloud_elastic_ip.disassociate_form
title: 'Disassociate Elastic Ip'
appears_on:
- entity.aws_cloud_elastic_ip.add_form
- entity.aws_cloud_elastic_ip.edit_form
entity.aws_cloud_elastic_ip.refresh:
route_name: aws_cloud.updateElasticIpList
title: 'Refresh'
......
......@@ -325,7 +325,7 @@ entity.aws_cloud_elastic_ip.associate_form:
_entity_form: 'aws_cloud_elastic_ip.associate'
_title: 'Associate AWS Cloud Elastic IP'
requirements:
_entity_access: 'aws_cloud_elastic_ip.edit'
_entity_access: 'aws_cloud_elastic_ip.associate'
entity.aws_cloud_elastic_ip.disassociate_form:
......@@ -334,7 +334,7 @@ entity.aws_cloud_elastic_ip.disassociate_form:
_entity_form: 'aws_cloud_elastic_ip.disassociate'
_title: 'Disassociate AWS Cloud Elastic IP'
requirements:
_entity_access: 'aws_cloud_elastic_ip.edit'
_entity_access: 'aws_cloud_elastic_ip.disassociate'
# AWS Cloud Security Groups Routes
......
<?php
// Updated by yas 2016/05/25
// created by yas 2016/05/19.
namespace Drupal\aws_cloud\Controller\Ec2;
use Drupal\Core\Entity\EntityAccessControlHandler;
......@@ -31,6 +29,24 @@ class ElasticIpAccessControlHandler extends EntityAccessControlHandler {
case 'delete':
return AccessResult::allowedIfHasPermissions($account, ['delete aws cloud elastic ip', 'view ' . $entity->getCloudContext()]);
case 'associate':
if ($entity->getAssociationId() == NULL) {
return AccessResult::allowedIfHasPermissions($account, [
'edit aws cloud elastic ip',
'view ' . $entity->getCloudContext(),
]);
}
return AccessResult::neutral();
case 'disassociate':
if ($entity->getAssociationId() != NULL) {
return AccessResult::allowedIfHasPermissions($account, [
'edit aws cloud elastic ip',
'view ' . $entity->getCloudContext(),
]);
}
return AccessResult::neutral();
}
// Unknown operation, no opinion.
return AccessResult::neutral();
......@@ -39,7 +55,7 @@ class ElasticIpAccessControlHandler extends EntityAccessControlHandler {
/**
* Not being used anymore.
*
* Access check is performed in \Drupal\cloud\Controller\CloudConfigController::access
* Access check is performed in \Drupal\cloud\Controller\CloudConfigController::access.
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add aws cloud elastic ip');
......
......@@ -10,7 +10,9 @@ use Drupal\Core\Messenger\Messenger;
use Drupal\cloud\Service\EntityLinkRendererInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\cloud\Plugin\CloudConfigPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -26,6 +28,8 @@ class AwsCloudContentForm extends CloudContentForm {
protected $awsEc2Service;
/**
* Entity link renderer object.
*
* @var \Drupal\cloud\Service\EntityLinkRendererInterface
*/
protected $entityLinkRenderer;
......@@ -37,6 +41,27 @@ class AwsCloudContentForm extends CloudContentForm {
*/
protected $entityTypeManager;
/**
* A plugin cache clear instance.
*
* @var \Drupal\Core\Plugin\CachedDiscoveryClearerInterface
*/
protected $pluginCacheClearer;
/**
* A cache backend interface instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheRender;
/**
* The cloud config plugin manager service.
*
* @var \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface
*/
protected $cloudConfigPluginManager;
/**
* AwsCloudContentForm constructor.
*
......@@ -52,17 +77,29 @@ class AwsCloudContentForm extends CloudContentForm {
* The entity link render service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity Type Manager.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender
* A cache backend interface instance.
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* A plugin cache clear instance.
* @param \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud config plugin manager service.
*/
public function __construct(EntityManagerInterface $manager,
AwsEc2ServiceInterface $aws_ec2_service,
Messenger $messenger,
EntityRepositoryInterface $entity_repository,
EntityLinkRendererInterface $entity_link_renderer,
EntityTypeManagerInterface $entity_type_manager) {
EntityTypeManagerInterface $entity_type_manager,
CacheBackendInterface $cacheRender,
CachedDiscoveryClearerInterface $plugin_cache_clearer,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
parent::__construct($manager, $entity_repository, $messenger);
$this->awsEc2Service = $aws_ec2_service;
$this->entityLinkRenderer = $entity_link_renderer;
$this->entityTypeManager = $entity_type_manager;
$this->cacheRender = $cacheRender;
$this->pluginCacheClearer = $plugin_cache_clearer;
$this->cloudConfigPluginManager = $cloud_config_plugin_manager;
}
/**
......@@ -75,7 +112,10 @@ class AwsCloudContentForm extends CloudContentForm {
$container->get('messenger'),
$container->get('entity.repository'),
$container->get('entity.link_renderer'),
$container->get('entity_type.manager')
$container->get('entity_type.manager'),
$container->get('cache.render'),
$container->get('plugin.cache_clearer'),
$container->get('plugin.manager.cloud_config_plugin')
);
}
......@@ -92,7 +132,7 @@ class AwsCloudContentForm extends CloudContentForm {
}
/**
*
* Copy values from #type=item elements to its original element type.
*/
protected function copyFormItemValues(array $form) {
$original_entity = $this->manager
......@@ -126,4 +166,12 @@ class AwsCloudContentForm extends CloudContentForm {
}
}
/**
* Helper method to clear cache values.
*/
protected function clearCacheValues() {
$this->pluginCacheClearer->clearCachedDefinitions();
$this->cacheRender->invalidateAll();
}
}
......@@ -4,10 +4,14 @@ namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\aws_cloud\Service\AwsEc2ServiceInterface;
use Drupal\cloud\Form\CloudContentDeleteForm;
use Drupal\cloud\Plugin\CloudConfigPluginManagerInterface;
use Drupal\cloud\Service\EntityLinkRendererInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -40,6 +44,34 @@ class AwsDeleteForm extends CloudContentDeleteForm {
*/
protected $currentUser;
/**
* A plugin cache clear instance.
*
* @var \Drupal\Core\Plugin\CachedDiscoveryClearerInterface
*/
protected $pluginCacheClearer;
/**
* A cache backend interface instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheRender;
/**
* Entity link renderer object.
*
* @var \Drupal\cloud\Service\EntityLinkRendererInterface
*/
protected $entityLinkRenderer;
/**
* The cloud config plugin manager service.
*
* @var \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface
*/
protected $cloudConfigPluginManager;
/**
* AwsDeleteForm constructor.
*
......@@ -53,11 +85,31 @@ class AwsDeleteForm extends CloudContentDeleteForm {
* The entity repository service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity Type Manager.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender
* A cache backend interface instance.
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* A plugin cache clear instance.
* @param \Drupal\cloud\Service\EntityLinkRendererInterface $entity_link_renderer
* The entity link render service.
* @param \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud config plugin manager service.
*/
public function __construct(EntityManagerInterface $manager, AwsEc2ServiceInterface $aws_ec2_service, Messenger $messenger, EntityRepositoryInterface $entity_repository, EntityTypeManagerInterface $entity_type_manager) {
public function __construct(EntityManagerInterface $manager,
AwsEc2ServiceInterface $aws_ec2_service,
Messenger $messenger,
EntityRepositoryInterface $entity_repository,
EntityTypeManagerInterface $entity_type_manager,
CacheBackendInterface $cacheRender,
CachedDiscoveryClearerInterface $plugin_cache_clearer,
EntityLinkRendererInterface $entity_link_renderer,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
parent::__construct($manager, $entity_repository, $messenger);
$this->awsEc2Service = $aws_ec2_service;
$this->entityTypeManager = $entity_type_manager;
$this->entityLinkRenderer = $entity_link_renderer;
$this->cacheRender = $cacheRender;
$this->pluginCacheClearer = $plugin_cache_clearer;
$this->cloudConfigPluginManager = $cloud_config_plugin_manager;
}
/**
......@@ -69,8 +121,20 @@ class AwsDeleteForm extends CloudContentDeleteForm {
$container->get('aws_cloud.ec2'),
$container->get('messenger'),
$container->get('entity.repository'),
$container->get('entity_type.manager')
$container->get('entity_type.manager'),
$container->get('cache.render'),
$container->get('plugin.cache_clearer'),
$container->get('entity.link_renderer'),
$container->get('plugin.manager.cloud_config_plugin')
);
}
/**
* Helper method to clear cache values.
*/
protected function clearCacheValues() {
$this->pluginCacheClearer->clearCachedDefinitions();
$this->cacheRender->invalidateAll();
}
}
......@@ -205,6 +205,7 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
'@private_ip' => $private_ip,
]);
$this->updateElasticIpEntity($message);
$this->clearCacheValues();
}
else {
$this->messenger->addError($this->t('Unable to associate elastic ip'));
......@@ -233,6 +234,7 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
'@private_ip' => $network_private_ip,
]);
$this->updateElasticIpEntity($message);
$this->clearCacheValues();
}
else {
$this->messenger->addError($this->t('Unable to associate elastic ip'));
......
<?php
// Updated by yas 2016/06/24
// Updated by yas 2016/06/03
// Updated by yas 2016/05/31
// Updated by yas 2016/05/30
// Updated by yas 2016/05/25
// Updated by yas 2016/05/23
// Updated by yas 2016/05/21
// Updated by yas 2016/05/20
// Created by yas 2016/05/19.
namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\Core\Form\FormStateInterface;
......@@ -87,6 +78,18 @@ class ElasticIpCreateForm extends AwsCloudContentForm {
&& ($entity->setAllocationId($result['AllocationId']))
&& ($entity->setDomain($result['Domain']))
&& ($entity->save())) {
// Update the Name tag.
$this->awsEc2Service->createTags([
'Resources' => [$entity->getAllocationId()],
'Tags' => [
[
'Key' => 'Name',
'Value' => $entity->getName(),
],
],
]);
$message = $this->t('The @label "%label (@elastic_ip)" has been created.', [
'@label' => $entity->getEntityType()->getLabel(),
'%label' => $entity->label(),
......
......@@ -25,13 +25,26 @@ class ElasticIpDisassociateForm extends AwsDeleteForm {
*/
public function getDescription() {
$entity = $this->entity;
$msg = '<h2>Elastic IP Information:</h2>';
$msg .= '<ul><li>Instance Id: @instance_id</li><li>Network Id: @network_id</li></ul>';
$instance_id = $entity->getInstanceId();
$network_interface_id = $entity->getNetworkInterfaceId();
$instance = $this->getInstanceById($instance_id);
$instance_link = $this->entityLinkRenderer->renderViewElement(
$instance_id,
'aws_cloud_instance',
'instance_id',
[],
$instance->getName() != $instance->getInstanceId() ? $this->t('@instance_name (@instance_id)', [
'@instance_name' => $instance->getName(),
'@instance_id' => $instance_id,
]) : $instance_id
);
$msg = '<h2>Elastic IP Information:</h2>';
$msg .= '<ul><li>Instance Id: ' . $instance_link['#markup'] . '</li><li>Network Id: @network_id</li></ul>';
return $this->t($msg, [
'@instance_id' => $instance_id,
':instance_id' => $instance_link['#markup'],
'@network_id' => $network_interface_id,
]);
}
......@@ -80,6 +93,8 @@ class ElasticIpDisassociateForm extends AwsDeleteForm {
$this->awsEc2Service->updateElasticIp();
$this->awsEc2Service->updateInstances();
$this->awsEc2Service->updateNetworkInterfaces();
$this->clearCacheValues();
}
else {
$this->messenger->addError($this->t('Unable to disassociated elastic ip.'));
......@@ -87,4 +102,22 @@ class ElasticIpDisassociateForm extends AwsDeleteForm {
$form_state->setRedirect('view.aws_elastic_ip.page_1', ['cloud_context' => $entity->getCloudContext()]);
}
/**
* Helper method to load instance by id.
*
* @param string $instance_id
* Instance Id to load.
*
* @return \Drupal\aws_cloud\Entity\Ec2\Instance
* Instance object.
*/
private function getInstanceById($instance_id) {
$instances = $this->entityTypeManager->getStorage('aws_cloud_instance')
->loadByProperties([
'instance_id' => $instance_id,
'cloud_context' => $this->entity->getCloudContext(),
]);
return array_shift($instances);
}
}
<?php
// Updated by yas 2016/06/03
// Created by yas 2016/05/30.
namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\cloud\Form\CloudContentForm;
use Drupal\Core\Form\FormStateInterface;
/**
......@@ -12,7 +9,7 @@ use Drupal\Core\Form\FormStateInterface;
*
* @ingroup aws_cloud
*/
class ElasticIpEditForm extends CloudContentForm {
class ElasticIpEditForm extends AwsCloudContentForm {
/**
* Overrides Drupal\Core\Entity\EntityFormController::buildForm().
......@@ -24,74 +21,72 @@ class ElasticIpEditForm extends CloudContentForm {
$entity = $this->entity;
$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,
'#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,
];
$form['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
'#size' => 60,
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
'#size' => 60,
'#default_value' => $entity->label(),
'#weight' => -5,
'#weight' => -5,
];
$form['public_ip'] = [
'#type' => 'textfield',
'#title' => $this->t('Elastic IP'),
'#maxlength' => 15,
'#size' => 60,
'#type' => 'textfield',
'#title' => $this->t('Elastic IP'),
'#maxlength' => 15,
'#size' => 60,
'#default_value' => $entity->getPublicIp(),
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
];
$form['domain'] = [
'#type' => 'textfield',
'#title' => $this->t('Domain (standard | vpc)'),
'#maxlength' => 64,
'#size' => 60,
'#type' => 'textfield',
'#title' => $this->t('Domain (standard | vpc)'),
'#maxlength' => 64,
'#size' => 60,
'#default_value' => $entity->getDomain(),
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
];
$form['allocation_id'] = [
'#type' => 'textfield',
'#title' => $this->t('Allocation ID'),
'#maxlength' => 64,
'#size' => 60,
'#type' => 'textfield',
'#title' => $this->t('Allocation ID'),
'#maxlength' => 64,
'#size' => 60,
'#default_value' => $entity->getAllocationId(),
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
];
$form['instance_id'] = [
'#type' => 'textfield',
'#title' => $this->t('Instance ID'),
'#maxlength' => 64,
'#size' => 60,
'#type' => 'textfield',
'#title' => $this->t('Instance ID'),
'#maxlength' => 64,
'#size' => 60,
'#default_value' => $entity->getInstanceId(),
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
'#required' => FALSE,
'#weight' => -5,
'#attributes' => ['readonly' => 'readonly'],
'#disabled' => TRUE,
];
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
......@@ -104,4 +99,23 @@ class ElasticIpEditForm extends CloudContentForm {
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
$this->awsEc2Service->setCloudContext($this->entity->getCloudContext());
// Update the Name tag.
$this->awsEc2Service->createTags([
'Resources' => [$this->entity->getAllocationId()],
'Tags' => [
[
'Key' => 'Name',
'Value' => $this->entity->getName(),
],
],
]);
}
}
<?php
// Updated by yas 2016/06/12
// Updated by yas 2016/05/31
// Updated by yas 2016/05/31
// Updated by yas 2016/05/30
// Updated by yas 2016/05/25
// Updated by yas 2016/05/23
// Updated by yas 2016/05/21
// Updated by yas 2016/05/20
// Created by yas 2016/05/19.
namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\cloud\Plugin\CloudConfigPluginManagerInterface;
use Drupal\aws_cloud\Service\AwsEc2ServiceInterface;
use Drupal\cloud\Service\EntityLinkRendererInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for the Image entity create form.
......@@ -30,60 +11,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class ImageCreateForm extends AwsCloudContentForm {
/**
* The cloud config plugin manager service.
*
* @var \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface
*/
protected $cloudConfigPluginManager;
/**
* ImageDeleteForm constructor.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $manager
* The Entity Manager.
* @param \Drupal\aws_cloud\Form\Ec2\AwsEc2ServiceInterface $aws_ec2_service
* The AWS EC2 Service.
* @param \Drupal\Core\Messenger\Messenger $messenger
* The Messenger serice.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud config plugin manager service.
* @param \Drupal\cloud\Service\EntityLinkRendererInterface $entity_link_renderer
* The entity link render service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity Type Manager.
*/
public function __construct(
EntityManagerInterface $manager,
AwsEc2ServiceInterface $aws_ec2_service,
Messenger $messenger,
EntityRepositoryInterface $entity_repository,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager,
EntityLinkRendererInterface $entity_link_renderer,
EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($manager, $aws_ec2_service, $messenger, $entity_repository, $entity_link_renderer, $entity_type_manager);
$this->cloudConfigPluginManager = $cloud_config_plugin_manager;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('aws_cloud.ec2'),
$container->get('messenger'),
$container->get('entity.repository'),
$container->get('plugin.manager.cloud_config_plugin'),
$container->get('entity.link_renderer'),
$container->get('entity_type.manager')
);
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::buildForm().
*/
......@@ -145,7 +72,7 @@ class ImageCreateForm extends AwsCloudContentForm {
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
......
<?php
// Updated by yas 2016/05/31
// Updated by yas 2016/05/30
// updated by yas 2016/05/29
// updated by yas 2016/05/28
// updated by yas 2016/05/25
// updated by yas 2016/05/21
// created by yas 2016/05/19.
namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\cloud\Plugin\CloudConfigPluginManagerInterface;
use Drupal\aws_cloud\Service\AwsEc2ServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for deleting a Image entity.
......@@ -28,53 +11,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class ImageDeleteForm extends AwsDeleteForm {
/**
* The cloud config plugin manager service.
*
* @var \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface
*/
protected $cloudConfigPluginManager;
/**
* ImageDeleteForm constructor.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $manager
* The Entity Manager.
* @param \Drupal\aws_cloud\Service\AwsEc2ServiceInterface $aws_ec2_service
* The AWS EC2 Service.
* @param \Drupal\Core\Messenger\Messenger $messenger
* The Messenger service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud config plugin manager service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity Type Manager.
*/
public function __construct(EntityManagerInterface $manager,
AwsEc2ServiceInterface $aws_ec2_service,
Messenger $messenger,
EntityRepositoryInterface $entity_repository,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager,
EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($manager, $aws_ec2_service, $messenger, $entity_repository, $entity_type_manager);
$this->cloudConfigPluginManager = $cloud_config_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('aws_cloud.ec2'),
$container->get('messenger'),
$container->get('entity.repository'),
$container->get('plugin.manager.cloud_config_plugin'),
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
......
......@@ -87,6 +87,7 @@ class InstanceAssociateElasticIpForm extends AwsDeleteForm {
'@private_ip' => $elastic_ip->getPrivateIpAddress(),
]);
$this->messenger->addMessage($message);
$this->clearCacheValues();
}
}
else {
......
......@@ -181,7 +181,10 @@ class InstanceEditForm extends AwsCloudContentForm {
$entity->getPublicIp(),
'aws_cloud_elastic_ip',
'public_ip',
['#title' => $this->t('Elastic IP: ')]
[
'#title' => $this->t('Elastic IP: '),
],
$current_elastic_ip->getName()
);
}
}
......@@ -466,6 +469,7 @@ class InstanceEditForm extends AwsCloudContentForm {
$this->awsEc2Service->updateElasticIp();
$this->awsEc2Service->updateInstances();
$this->awsEc2Service->updateNetworkInterfaces();
$this->clearCacheValues();
}
}
}
......
......@@ -1515,6 +1515,18 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
if (isset($stale[$elastic_ip['PublicIp']])) {
unset($stale[$elastic_ip['PublicIp']]);
}
$elastic_ip_name = '';
if (isset($elastic_ip['Tags'])) {
foreach ($elastic_ip['Tags'] as $tag) {
if ($tag['Key'] == 'Name') {
$elastic_ip_name = $tag['Value'];
}
}
}
// Default to instance_id.
if (empty($elastic_ip_name)) {
$elastic_ip_name = $elastic_ip['PublicIp'];
}
$entity_id = $this->getEntityId($entity_type, 'public_ip', $elastic_ip['PublicIp']);
......@@ -1523,6 +1535,7 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
$entity = ElasticIp::load($entity_id);
// Update fields.
$entity->setName($elastic_ip_name);
$entity->setInstanceId(!empty($elastic_ip['InstanceId']) ? $elastic_ip['InstanceId'] : '');
$entity->setNetworkInterfaceId(!empty($elastic_ip['NetworkInterfaceId']) ? $elastic_ip['NetworkInterfaceId'] : '');
$entity->setPrivateIpAddress(!empty($elastic_ip['PrivateIpAddress']) ? $elastic_ip['PrivateIpAddress'] : '');
......@@ -1538,7 +1551,7 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
$entity = ElasticIp::create([
'cloud_context' => $this->cloudContext,
'name' => $elastic_ip['PublicIp'],
'name' => $elastic_ip_name,
'public_ip' => $elastic_ip['PublicIp'],
'instance_id' => !empty($elastic_ip['InstanceId']) ? $elastic_ip['InstanceId'] : '',
'network_interface_id' => !empty($elastic_ip['NetworkInterfaceId']) ? $elastic_ip['NetworkInterfaceId'] : '',
......
......@@ -60,7 +60,8 @@ class EntityLinkRenderer implements EntityLinkRendererInterface {
$value,
$target_type,
$field_name,
array $query = []) {
array $query = [],
$alt_text = '') {
$cloud_context = $this->routeMatch->getParameter('cloud_context');
......@@ -84,7 +85,7 @@ class EntityLinkRenderer implements EntityLinkRendererInterface {
}
else {
$htmls[] = $this->linkGenerator->generate(
$value,
!empty($alt_text) ? $alt_text : $value,
Url::fromRoute(
"entity.$target_type.canonical",
[
......@@ -109,9 +110,10 @@ class EntityLinkRenderer implements EntityLinkRendererInterface {
$value,
$target_type,
$field_name,
array $options) {
array $options,
$alt_text = '') {
return $this->renderViewElement($value, $target_type, $field_name)
return $this->renderViewElement($value, $target_type, $field_name, $options, $alt_text)
+ $options
+ ['#type' => 'item'];
}
......
......@@ -18,11 +18,13 @@ interface EntityLinkRendererInterface {
* The field name of target entity.
* @param array $query
* The query parameters.
* @param string $alt_text
* Optional alternative text to display.
*
* @return array
* The build array of entity link element for viewZ.
*/
public function renderViewElement($value, $target_type, $field_name, array $query);
public function renderViewElement($value, $target_type, $field_name, array $query, $alt_text = '');
/**
* Render entity link for form.
......@@ -35,6 +37,8 @@ interface EntityLinkRendererInterface {
* The field name of target entity.
* @param array $options
* The form element options.
* @param string $alt_text
* Alternative text to display.
*
* @return array
* The build array of entity link element for form.
......@@ -43,7 +47,8 @@ interface EntityLinkRendererInterface {
$value,
$target_type,
$field_name,
array $options
array $options,
$alt_text = ''
);
}
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