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

Issue #3070465 by Xiaohua Guan, yas, baldwinlouie: Add an Entity Link for VPC...

Issue #3070465 by Xiaohua Guan, yas, baldwinlouie: Add an Entity Link for VPC and Subnet in ServerTemplate views
parent cf1f9093
No related branches found
No related tags found
No related merge requests found
......@@ -1236,6 +1236,18 @@ function aws_cloud_update_8171() {
cloud_update_yml_definitions($files, 'aws_cloud');
}
/**
* Update entity view display of cloud_server_template.aws_ec2.default.
*
* Add entity links to field_vpc and field_subnet.
*/
function aws_cloud_update_8172() {
$files = [
'core.entity_view_display.cloud_server_template.aws_cloud.default.yml',
];
cloud_update_yml_definitions($files, 'aws_cloud');
}
/**
* Helper function to add fields to the entity type.
*
......
......@@ -147,9 +147,13 @@ content:
field_subnet:
weight: 17
label: inline
settings: { }
settings:
target_type: aws_cloud_subnet
field_name: subnet_id
html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithNameHtmlGenerator
comma_separated: false
third_party_settings: { }
type: list_default
type: entity_link
region: content
field_test_only:
weight: 2
......@@ -171,9 +175,13 @@ content:
field_vpc:
weight: 18
label: inline
settings: { }
settings:
target_type: aws_cloud_vpc
field_name: vpc_id
html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithNameHtmlGenerator
comma_separated: false
third_party_settings: { }
type: list_default
type: entity_link
region: content
field_termination_protection:
weight: 19
......
......@@ -177,7 +177,23 @@ class AwsCloudServerTemplateListBuilder extends CloudServerTemplateListBuilder {
$row[] = '';
}
$row[] = $entity->get('field_vpc')->value;
// VPC.
if ($entity->get('field_vpc')->value != NULL) {
$row[] = [
'data' => $this->entityLinkRenderer->renderViewElement(
$entity->get('field_vpc')->value,
'aws_cloud_vpc',
'vpc_id',
[],
'',
'Drupal\cloud\Service\Util\EntityLinkWithShortNameHtmlGenerator'
),
];
}
else {
$row[] = '';
}
$row[] = $entity->get('field_max_count')->value;
$row[] = $parent_row['operations'];
......
......@@ -336,15 +336,7 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
*/
private function getNameFromArray(array $array, $index, $id_key_name) {
// Get id.
$id = $array[$index][$id_key_name];
// Get name if Tags exists.
$name = $id;
if (isset($array[$index]['Tags'])) {
$name = $array[$index]['Tags'][0]['Value'];
}
return sprintf('%s (%s)', $name, $id);
return $array[$index][$id_key_name];
}
}
......@@ -18,7 +18,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* id = "entity_link",
* label = @Translation("Entity link"),
* field_types = {
* "string"
* "string",
* "list_string",
* }
* )
*/
......@@ -137,7 +138,7 @@ class EntityLinkFormatter extends FormatterBase implements ContainerFactoryPlugi
];
$element['html_generator_class'] = [
'#title' => $this->t('Display name'),
'#title' => $this->t('HTML generator class'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('html_generator_class'),
];
......
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