Skip to content
Snippets Groups Projects
Commit 36a64430 authored by Yoftahe Akalu's avatar Yoftahe Akalu Committed by Yas Naoi
Browse files

Issue #3119979 by nilesh.addweb, amit.drupal, yas: Refactor to add a link to...

Issue #3119979 by nilesh.addweb, amit.drupal, yas: Refactor to add a link to the message when associating an EIP
parent 41195091
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\aws_cloud\Entity\Ec2\Instance;
use Drupal\aws_cloud\Entity\Ec2\NetworkInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Markup;
/**
* Associate Elastic IP address.
......@@ -202,13 +203,29 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->ec2Service->setCloudContext($this->entity->getCloudContext());
$entity = $this->entity;
// Determine if elastic_ip is attaching to instance or network_interface.
if ($form_state->getValue('resource_type') === 'instance') {
$instance_id = $form_state->getValue('instance_id');
$get_instance_id = $form_state->getValue('instance_id');
$private_ip = $form_state->getValue('instance_private_ip');
if ($instance_id !== -1) {
$instance = Instance::load($instance_id);
$instance = Instance::load($get_instance_id);
$instance_id = $instance->getInstanceId();
$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
);
// Refresh network interfaces.
$this->ec2Service->updateNetworkInterfaces();
......@@ -222,11 +239,12 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
]);
if (!empty($result)) {
$message = $this->t('Elastic IP @ip_address associated with @private_ip for instance: @instance', [
$message = $this->t('Elastic IP @ip_address associated with @private_ip for instance: @instance_id', [
'@ip_address' => $this->entity->getPublicIp(),
'@instance' => !empty($instance) ? $instance->getName() : 'N/A',
'@private_ip' => $private_ip,
'@instance_id' => Markup::create($instance_link['#markup']),
]);
$this->updateElasticIpEntity($message);
$this->clearCacheValues();
}
......
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