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

Issue #3015491 by Xiaohua Guan, yas: Fix an error at ServerTemplate: "The...

Issue #3015491 by Xiaohua Guan, yas: Fix an error at ServerTemplate: "The website encountered an unexpected error. Please try again later."
parent 97f9db9a
No related branches found
No related tags found
No related merge requests found
......@@ -25,16 +25,16 @@ view published cloud server template entities:
view unpublished cloud server template entities:
title: 'View unpublished Cloud Server Template entities'
view all cloud server template revisions:
title: 'View all Cloud Server Template revisions'
access cloud server template revisions:
title: 'Access Cloud Server Template revisions'
revert all cloud server template revisions:
title: 'Revert all Cloud Server Template revisions'
description: 'Role requires permission <em>view Cloud Server Template revisions</em> and <em>edit rights</em> for cloud server template entities in question or <em>administer cloud server template entities</em>.'
description: 'Role requires permission <em>access Cloud Server Template revisions</em> and <em>edit rights</em> for cloud server template entities in question or <em>administer cloud server template entities</em>.'
delete all cloud server template revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view Cloud Server Template revisions</em> and <em>delete rights</em> for cloud server template entities in question or <em>administer cloud server template entities</em>.'
description: 'Role requires permission to <em>access Cloud Server Template revisions</em> and <em>delete rights</em> for cloud server template entities in question or <em>administer cloud server template entities</em>.'
launch server template:
title: 'Launch server template'
......
......@@ -127,7 +127,11 @@ class CloudServerTemplateController extends ControllerBase implements ContainerI
// Use revision link to link to revisions that are not active.
$date = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short');
if ($vid != $cloud_server_template->getRevisionId()) {
$link = $this->l($date, new Url('entity.cloud_server_template.revision', ['cloud_server_template' => $cloud_server_template->id(), 'cloud_server_template_revision' => $vid]));
$link = $this->l($date, new Url('entity.cloud_server_template.revision', [
'cloud_context' => $cloud_server_template->cloud_context(),
'cloud_server_template' => $cloud_server_template->id(),
'cloud_server_template_revision' => $vid,
]));
}
else {
$link = $cloud_server_template->link($date);
......@@ -165,16 +169,29 @@ class CloudServerTemplateController extends ControllerBase implements ContainerI
if ($revert_permission) {
$links['revert'] = [
'title' => $this->t('Revert'),
'url' => $has_translations ?
Url::fromRoute('entity.cloud_server_template.translation_revert', ['cloud_server_template' => $cloud_server_template->id(), 'cloud_server_template_revision' => $vid, 'langcode' => $langcode]) :
Url::fromRoute('entity.cloud_server_template.revision_revert', ['cloud_server_template' => $cloud_server_template->id(), 'cloud_server_template_revision' => $vid]),
'url' => $has_translations
? Url::fromRoute('entity.cloud_server_template.translation_revert', [
'cloud_context' => $cloud_server_template->cloud_context(),
'cloud_server_template' => $cloud_server_template->id(),
'cloud_server_template_revision' => $vid,
'langcode' => $langcode,
])
: Url::fromRoute('entity.cloud_server_template.revision_revert', [
'cloud_context' => $cloud_server_template->cloud_context(),
'cloud_server_template' => $cloud_server_template->id(),
'cloud_server_template_revision' => $vid,
]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('entity.cloud_server_template.revision_delete', ['cloud_server_template' => $cloud_server_template->id(), 'cloud_server_template_revision' => $vid]),
'url' => Url::fromRoute('entity.cloud_server_template.revision_delete', [
'cloud_context' => $cloud_server_template->cloud_context(),
'cloud_server_template' => $cloud_server_template->id(),
'cloud_server_template_revision' => $vid,
]),
];
}
......
......@@ -59,11 +59,11 @@ use Drupal\user\UserInterface;
* "add-form" = "/clouds/design/server_template/add/{cloud_context}/{cloud_server_template_type}",
* "edit-form" = "/clouds/design/server_template/edit/{cloud_context}/{cloud_server_template}",
* "delete-form" = "/clouds/design/server_template/delete/{cloud_context}/{cloud_server_template}",
* "version-history" = "/clouds/design/server_template/{cloud_server_template}/revisions",
* "revision" = "/clouds/design/server_template/{cloud_server_template}/revisions/{cloud_server_template_revision}/view",
* "revision_revert" = "/clouds/design/server_template/{cloud_server_template}/revisions/{cloud_server_template_revision}/revert",
* "revision_delete" = "/clouds/design/server_template/{cloud_server_template}/revisions/{cloud_server_template_revision}/delete",
* "translation_revert" = "/clouds/design/server_template/{cloud_server_template}/revisions/{cloud_server_template_revision}/revert/{langcode}",
* "version-history" = "/clouds/design/server_template/{cloud_context}/{cloud_server_template}/revisions",
* "revision" = "/clouds/design/server_template/{cloud_context}/{cloud_server_template}/revisions/{cloud_server_template_revision}/view",
* "revision_revert" = "/clouds/design/server_template/{cloud_context}/{cloud_server_template}/revisions/{cloud_server_template_revision}/revert",
* "revision_delete" = "/clouds/design/server_template/{cloud_context}/{cloud_server_template}/revisions/{cloud_server_template_revision}/delete",
* "translation_revert" = "/clouds/design/server_template/{cloud_context}/{cloud_server_template}/revisions/{cloud_server_template_revision}/revert/{langcode}",
* "collection" = "/clouds/design/server_template/list",
* "launch" = "/clouds/design/server_template/{cloud_context}/{cloud_server_template}/launch",
* },
......
......@@ -95,7 +95,10 @@ class CloudServerTemplateRevisionDeleteForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.cloud_server_template.version_history', ['cloud_server_template' => $this->revision->id()]);
return new Url('entity.cloud_server_template.version_history', [
'cloud_context' => $this->revision->cloud_context(),
'cloud_server_template' => $this->revision->id(),
]);
}
/**
......@@ -129,8 +132,10 @@ class CloudServerTemplateRevisionDeleteForm extends ConfirmFormBase {
);
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {cloud_server_template_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
$form_state->setRedirect(
'entity.cloud_server_template.version_history',
['cloud_server_template' => $this->revision->id()]
'entity.cloud_server_template.version_history', [
'cloud_context' => $this->revision->cloud_context(),
'cloud_server_template' => $this->revision->id(),
]
);
}
}
......
......@@ -95,7 +95,10 @@ class CloudServerTemplateRevisionRevertForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.cloud_server_template.version_history', ['cloud_server_template' => $this->revision->id()]);
return new Url('entity.cloud_server_template.version_history', [
'cloud_context' => $this->revision->cloud_context(),
'cloud_server_template' => $this->revision->id(),
]);
}
/**
......@@ -137,8 +140,10 @@ class CloudServerTemplateRevisionRevertForm extends ConfirmFormBase {
$this->logger('content')->notice('Cloud Server Template: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
$this->messenger->addMessage(t('Cloud Server Template %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
$form_state->setRedirect(
'entity.cloud_server_template.version_history',
['cloud_server_template' => $this->revision->id()]
'entity.cloud_server_template.version_history', [
'cloud_context' => $this->revision->cloud_context(),
'cloud_server_template' => $this->revision->id(),
]
);
}
......
......@@ -44,6 +44,9 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
'view unpublished cloud server template entities',
'edit cloud server template entities',
'delete cloud server template entities',
'access cloud server template revisions',
'revert all cloud server template revisions',
'delete all cloud server template revisions',
];
}
......@@ -158,6 +161,98 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
}
}
/**
* Tests CRUD for server_template revision information.
*/
public function testCloudServerTemplateRevision() {
$cloud_context = $this->cloud_context;
$this->createImage();
// Create a server template.
$add = $this->createServerTemplateTestData();
$this->drupalPostForm("/clouds/design/server_template/add/$cloud_context/aws_cloud",
$add[0],
t('Save'));
$this->assertResponse(200, t('HTTP 200: Add | A New CloudServerTemplate Form #@num', ['@num' => 1]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText(t('Created the @name Cloud Server Template', [
'@name' => $add[0]['name[0][value]'],
]),
t('Confirm Message') . ': '
. t('Created the @name Cloud Server Template', [
'@name' => $add[0]['name[0][value]'],
]));
// Make sure listing revisions.
$this->drupalGet("/clouds/design/server_template/$cloud_context/1/revisions");
$this->assertResponse(200, t('HTTP 200: List | Server Template Revision'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
// Create a new revision.
$edit = $add[0];
$old_description = $edit['field_description[0][value]'];
$revision_desc = $this->random->name(32, TRUE);
$edit['field_description[0][value]'] = $revision_desc;
$edit['new_revision'] = '1';
$this->drupalPostForm("/clouds/design/server_template/edit/$cloud_context/1",
$edit,
t('Save'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText(t('Saved the @name Cloud Server Template.', [
'@name' => $edit['name[0][value]'],
]),
t('Confirm Message') . ': '
. t('Saved the @name Cloud Server Template.', [
'@name' => $edit['name[0][value]'],
]));
// Make sure listing revisions.
$this->drupalGet("/clouds/design/server_template/$cloud_context/1/revisions");
$this->assertResponse(200, t('HTTP 200: List | Server Template Revision'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertSession()->linkByHrefExists("server_template/$cloud_context/1/revisions/1/view");
$this->assertSession()->linkByHrefExists("server_template/$cloud_context/1/revisions/1/revert");
$this->assertSession()->linkByHrefExists("server_template/$cloud_context/1/revisions/1/delete");
// View the revision.
$this->drupalGet("/clouds/design/server_template/$cloud_context/1/revisions/1/view");
$this->assertResponse(200, t('HTTP 200: View | Server Template Revision'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText($old_description);
// Revert the revision.
$this->drupalPostForm("/clouds/design/server_template/$cloud_context/1/revisions/1/revert",
[],
t('Revert'));
$this->assertResponse(200, t('HTTP 200: List | Server Template Revision'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText(t('Cloud Server Template @name has been reverted', [
'@name' => $edit['name[0][value]'],
]));
// A new revision is created.
$this->assertSession()->linkByHrefExists("server_template/$cloud_context/1/revisions/2/view");
// Delete the revision.
$this->drupalPostForm("/clouds/design/server_template/$cloud_context/1/revisions/1/delete",
[],
t('Delete'));
$this->assertResponse(200, t('HTTP 200: List | Server Template Revision'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText(t('Cloud Server Template @name has been deleted.', [
'@name' => $edit['name[0][value]'],
]));
// The revision is deleted.
$this->assertSession()->linkByHrefNotExists("server_template/$cloud_context/1/revisions/1/view");
}
private function createServerTemplateTestData() {
$random = $this->random;
......
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