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

Issue #3053872 by Xiaohua Guan, yas, baldwinlouie: Launch a instance using a...

Issue #3053872 by Xiaohua Guan, yas, baldwinlouie: Launch a instance using a ServerTemplate with user data
parent cc0667fc
No related branches found
No related tags found
No related merge requests found
......@@ -689,6 +689,17 @@ function aws_cloud_update_8140() {
$config->save();
}
/**
* Update field_user_data in cloud_server_template entity view.
*/
function aws_cloud_update_8141() {
$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.
*
......
......@@ -165,7 +165,7 @@ content:
label: above
settings: { }
third_party_settings: { }
type: basic_string
type: pre_string_formatter
region: content
field_vpc:
weight: 18
......
......@@ -133,7 +133,7 @@ class AwsCloudServerTemplatePlugin extends PluginBase implements CloudServerTemp
$params['RamdiskId'] = $cloud_server_template->get('field_ram')->value;
}
if (isset($cloud_server_template->get('field_user_data')->value)) {
$params['UserData'] = $cloud_server_template->get('field_user_data')->value;
$params['UserData'] = base64_encode($cloud_server_template->get('field_user_data')->value);
}
if (isset($cloud_server_template->get('field_availability_zone')->value)) {
$params['Placement']['AvailabilityZone'] = $cloud_server_template->get('field_availability_zone')->value;
......
<?php
namespace Drupal\aws_cloud\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
/**
* Plugin implementation of the 'pre_string_formatter' formatter.
*
* This formatter use PRE tag to surround content.
*
* @FieldFormatter(
* id = "pre_string_formatter",
* label = @Translation("PRE tag string formatter"),
* field_types = {
* "string_long",
* }
* )
*/
class PreStringFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => '<pre>' . $item->value . '</pre>',
];
}
return $elements;
}
}
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