Skip to content
Snippets Groups Projects
Commit ebc13542 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3306702 by Xiaohua Guan, yas, kumikoono: Fix the labels in OpenStack...

Issue #3306702 by Xiaohua Guan, yas, kumikoono: Fix the labels in OpenStack instance detail view and launch template (Flavor and Image name)
parent 389e802c
No related branches found
No related tags found
2 merge requests!1316Issue #3310263: Release 4.5.0,!1245Issue #3306702 by Xiaohua Guan, yas: Refactor openstack instance and launch template
......@@ -874,6 +874,7 @@ function openstack_entity_view(array &$build, EntityInterface $entity, EntityVie
function openstack_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display): void {
if ($entity->getEntityTypeId() === 'cloud_launch_template' && $entity->bundle() === 'openstack') {
\Drupal::service('cloud')->reorderForm($build, openstack_launch_template_field_orders(FALSE));
unset($build['field_instance_type']);
$build['#attached']['library'][] = 'aws_cloud/aws_cloud_view_builder';
}
}
......@@ -1169,8 +1170,9 @@ function openstack_form_cloud_launch_template_openstack_form_common_alter(array
unset($form['options']);
}
$form['instance']['field_instance_type']['widget']['#default_value'] = ['m1.nano'];
$form['instance']['field_instance_type']['#access'] = FALSE;
$form['field_instance_type']['widget']['#default_value'] = ['m1.nano'];
$form['field_instance_type']['#access'] = FALSE;
if (!empty($openstack_ec2_service)) {
$form['instance']['field_flavor']['widget']['#default_value'] = '1';
$form['instance']['field_flavor']['#access'] = FALSE;
......@@ -2082,7 +2084,6 @@ function openstack_launch_template_field_orders($include_name = TRUE): array {
'fields' => [
'name',
'field_description',
'field_instance_type',
'field_flavor',
'field_min_count',
'field_max_count',
......@@ -2091,7 +2092,7 @@ function openstack_launch_template_field_orders($include_name = TRUE): array {
],
[
'name' => 'ami',
'title' => t('AMI'),
'title' => t('Image'),
'open' => TRUE,
'fields' => [
'field_openstack_image_id',
......
......@@ -4,6 +4,7 @@ namespace Drupal\openstack\Entity;
use Drupal\aws_cloud\Entity\Ec2\Instance;
use Drupal\aws_cloud\Entity\Ec2\InstanceInterface;
use Drupal\cloud\Service\Util\EntityLinkWithShortNameHtmlGenerator;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\aws_cloud\Entity\Ec2\PublicIpEntityLinkHtmlGenerator;
......@@ -78,7 +79,7 @@ class OpenStackInstance extends Instance implements InstanceInterface {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['instance_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Instance type'))
->setLabel(t('Flavor'))
->setDescription(t("The type of instance determines your instance's CPU capacity, memory, and storage (e.g., m1.small, c1.xlarge)."))
->setDisplayOptions('view', [
'label' => 'inline',
......@@ -186,6 +187,22 @@ class OpenStackInstance extends Instance implements InstanceInterface {
array_slice($fields, $pos + 1)
);
$fields['image_id'] = BaseFieldDefinition::create('string')
->setLabel(t('OpenStack Image Name'))
->setDescription(t('The Name of the OpenStack image with which the instance was launched.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'entity_link',
'settings' => [
'target_type' => 'openstack_image',
'field_name' => 'image_id',
'comma_separated' => TRUE,
'html_generator_class' => EntityLinkWithShortNameHtmlGenerator::class,
],
'weight' => -5,
])
->setReadOnly(TRUE);
return $fields;
}
......
......@@ -17,6 +17,12 @@ class OpenStackInstanceViewBuilder extends InstanceViewBuilder {
$defs[0]['fields'][] = 'power_state';
// Remove account_id.
$pos = array_search('account_id', $defs[0]['fields']);
if ($pos !== FALSE) {
unset($defs[0]['fields'][$pos]);
}
return $defs;
}
......
......@@ -23,7 +23,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
......@@ -405,14 +404,14 @@ class OpenStackLaunchTemplatePlugin extends CloudPluginBase implements CloudLaun
public function buildListHeader(): array {
return [
[
'data' => $this->t('AMI Name'),
'data' => $this->t('Image Name'),
'specifier' => 'field_openstack_image_id',
'field' => 'field_openstack_image_id',
],
[
'data' => $this->t('Instance type'),
'specifier' => 'field_instance_type',
'field' => 'field_instance_type',
'data' => $this->t('Flavor'),
'specifier' => 'field_flavor',
'field' => 'field_flavor',
],
[
'data' => $this->t('Security group'),
......@@ -469,18 +468,12 @@ class OpenStackLaunchTemplatePlugin extends CloudPluginBase implements CloudLaun
$row[] = $empty_row;
}
// Instance type.
$instance_type = $entity->get('field_instance_type')->value;
// Flavor.
$row[] = [
'data' => [
'#type' => 'link',
'#url' => Url::fromRoute(
'aws_cloud.instance_type_prices',
['cloud_context' => $entity->getCloudContext()],
['fragment' => $instance_type]
),
'#title' => $instance_type,
],
'data' => $entity->field_flavor->view([
'label' => 'hidden',
'type' => 'string',
]),
];
// Security groups.
......
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