Commit d9bf4087 authored by xjm's avatar xjm

Issue #2513402 by pixelmord, cilefen, prajaankit, jcnventura, webchick,...

Issue #2513402 by pixelmord, cilefen, prajaankit, jcnventura, webchick, nicrodgers, Bojhan, g.oechsler, xjm, ifrik, Wim Leers: Any time a user creates a thing and saves, display a link to the thing created in the status
parent 9e73da7b
......@@ -16,13 +16,16 @@ class FeedForm extends ContentEntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
$feed = $this->entity;
if ($feed->save() == SAVED_UPDATED) {
drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label())));
$status = $feed->save();
$label = $feed->label();
$view_link = $feed->link($label, 'canonical');
if ($status == SAVED_UPDATED) {
drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $view_link)));
$form_state->setRedirectUrl($feed->urlInfo('canonical'));
}
else {
$this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview'))));
drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label())));
drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $view_link)));
}
}
......
......@@ -61,7 +61,11 @@ protected function setUp() {
public function createFeed($feed_url = NULL, array $edit = array()) {
$edit = $this->getFeedEditArray($feed_url, $edit);
$this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
$this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title[0][value]'])), format_string('The feed @name has been added.', array('@name' => $edit['title[0][value]'])));
$this->assertText(t('The feed @name has been added.', array('@name' => $edit['title[0][value]'])), format_string('The feed @name has been added.', array('@name' => $edit['title[0][value]'])));
// Verify that the creation message contains a link to a feed.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'aggregator/sources/'));
$this->assert(isset($view_link), 'The message area contains a link to a feed');
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $edit['title[0][value]'], ':url' => $edit['url[0][value]']))->fetchField();
$this->assertTrue(!empty($fid), 'The feed found in database.');
......
......@@ -35,7 +35,11 @@ public function testUpdateFeedItem() {
$this->assertResponse(200);
$this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
$this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title[0][value]'])), format_string('The feed @name has been added.', array('@name' => $edit['title[0][value]'])));
$this->assertText(t('The feed @name has been added.', array('@name' => $edit['title[0][value]'])), format_string('The feed @name has been added.', array('@name' => $edit['title[0][value]'])));
// Verify that the creation message contains a link to a feed.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'aggregator/sources/'));
$this->assert(isset($view_link), 'The message area contains a link to a feed');
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url[0][value]']))->fetchField();
$feed = Feed::load($fid);
......
......@@ -24,7 +24,11 @@ public function testUpdateFeed() {
$edit[$same_field] = $feed->{$same_field}->value;
}
$this->drupalPostForm('aggregator/sources/' . $feed->id() . '/configure', $edit, t('Save'));
$this->assertRaw(t('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])), format_string('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])));
$this->assertText(t('The feed @name has been updated.', array('@name' => $edit['title[0][value]'])), format_string('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])));
// Verify that the creation message contains a link to a feed.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'aggregator/sources/'));
$this->assert(isset($view_link), 'The message area contains a link to a feed');
// Check feed data.
$this->assertUrl($feed->url('canonical', ['absolute' => TRUE]));
......
......@@ -130,12 +130,13 @@ public function save(array $form, FormStateInterface $form_state) {
$contact_settings = $this->config('contact.settings');
$edit_link = $this->entity->link($this->t('Edit'));
$view_link = $contact_form->link($contact_form->label(), 'canonical');
if ($status == SAVED_UPDATED) {
drupal_set_message($this->t('Contact form %label has been updated.', array('%label' => $contact_form->label())));
drupal_set_message($this->t('Contact form %label has been updated.', array('%label' => $view_link)));
$this->logger('contact')->notice('Contact form %label has been updated.', array('%label' => $contact_form->label(), 'link' => $edit_link));
}
else {
drupal_set_message($this->t('Contact form %label has been added.', array('%label' => $contact_form->label())));
drupal_set_message($this->t('Contact form %label has been added.', array('%label' => $view_link)));
$this->logger('contact')->notice('Contact form %label has been added.', array('%label' => $contact_form->label(), 'link' => $edit_link));
}
......
......@@ -127,11 +127,19 @@ function testSiteWideContact() {
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName($max_length_exceeded)), $label = $this->randomMachineName($max_length_exceeded), implode(',', array($recipients[0])), '', TRUE);
$this->assertText(format_string('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', array('@max' => $max_length, '@exceeded' => $max_length_exceeded)));
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName($max_length)), $label = $this->randomMachineName($max_length), implode(',', array($recipients[0])), '', TRUE);
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
$this->assertText(t('Contact form @label has been added.', array('@label' => $label)));
// Verify that the creation message contains a link to a contact form.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'contact/'));
$this->assert(isset($view_link), 'The message area contains a link to a contact form.');
// Create first valid form.
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($recipients[0])), '', TRUE);
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
$this->assertText(t('Contact form @label has been added.', array('@label' => $label)));
// Verify that the creation message contains a link to a contact form.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'contact/'));
$this->assert(isset($view_link), 'The message area contains a link to a contact form.');
// Check that the form was created in site default language.
$langcode = $this->config('contact.form.' . $id)->get('langcode');
......@@ -152,7 +160,7 @@ function testSiteWideContact() {
$this->assertEqual($config['recipients'], array($recipients[0], $recipients[1]));
$this->assertEqual($config['reply'], $reply);
$this->assertNotEqual($id, $this->config('contact.settings')->get('default_form'));
$this->assertRaw(t('Contact form %label has been updated.', array('%label' => $label)));
$this->assertText(t('Contact form @label has been updated.', array('@label' => $label)));
// Ensure the label is displayed on the contact page for this form.
$this->drupalGet('contact/' . $id);
$this->assertText($label);
......@@ -170,14 +178,14 @@ function testSiteWideContact() {
// Add more forms.
$this->addContactForm(Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE);
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
$this->assertText(t('Contact form @label has been added.', array('@label' => $label)));
$this->addContactForm($name = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE);
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
$this->assertText(t('Contact form @label has been added.', array('@label' => $label)));
// Try adding a form that already exists.
$this->addContactForm($name, $label, '', '', FALSE);
$this->assertNoRaw(t('Contact form %label has been added.', array('%label' => $label)));
$this->assertNoText(t('Contact form @label has been added.', array('@label' => $label)));
$this->assertRaw(t('The machine-readable name is already in use. It must be unique.'));
$this->drupalLogout();
......
......@@ -50,7 +50,7 @@ public function testContactStorage() {
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($mail)), '', TRUE, [
'send_a_pony' => 1,
]);
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
$this->assertText(t('Contact form @label has been added.', array('@label' => $label)));
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
......
......@@ -294,7 +294,11 @@ function testFilterAdmin() {
$edit['body[0][value]'] = $text;
$edit['body[0][format]'] = $basic;
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$this->assertRaw(t('Basic page %title has been created.', array('%title' => $edit['title[0][value]'])), 'Filtered node created.');
$this->assertText(t('Basic page @title has been created.', array('@title' => $edit['title[0][value]'])), 'Filtered node created.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$this->assert(isset($view_link), 'The message area contains a link to a node');
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertTrue($node, 'Node found in database.');
......
......@@ -78,9 +78,10 @@ public function save(array $form, FormStateInterface $form_state) {
$route_name = $this->urlStub == 'container' ? 'entity.taxonomy_term.forum_edit_container_form' : 'entity.taxonomy_term.forum_edit_form';
$route_parameters = ['taxonomy_term' => $term->id()];
$link = $this->l($this->t('Edit'), new Url($route_name, $route_parameters));
$view_link = $term->link($term->getName());
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
drupal_set_message($this->t('Created new @type %term.', array('%term' => $view_link, '@type' => $this->forumFormType)));
$this->logger('forum')->notice('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link));
$form_state->setValue('tid', $term->id());
break;
......
......@@ -415,14 +415,18 @@ function createForum($type, $parent = 0) {
$this->drupalPostForm('admin/structure/forum/add/' . $type, $edit, t('Save'));
$this->assertResponse(200);
$type = ($type == 'container') ? 'forum container' : 'forum';
$this->assertRaw(
$this->assertText(
t(
'Created new @type %term.',
array('%term' => $name, '@type' => t($type))
'Created new @type @term.',
array('@term' => $name, '@type' => t($type))
),
format_string('@type was created', array('@type' => ucfirst($type)))
);
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Verify forum.
$term = db_query("SELECT * FROM {taxonomy_term_field_data} t WHERE t.vid = :vid AND t.name = :name AND t.description__value = :desc AND t.default_langcode = 1", array(':vid' => $this->config('forum.settings')->get('vocabulary'), ':name' => $name, ':desc' => $description))->fetchAssoc();
$this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
......@@ -540,13 +544,17 @@ function createForumTopic($forum, $container = FALSE) {
$type = t('Forum topic');
if ($container) {
$this->assertNoRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), 'Forum topic was not created');
$this->assertNoText(t('@type @title has been created.', array('@type' => $type, '@title' => $title)), 'Forum topic was not created');
$this->assertRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'Error message was shown');
return;
}
else {
$this->assertRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), 'Forum topic was created');
$this->assertText(t('@type @title has been created.', array('@type' => $type, '@title' => $title)), 'Forum topic was created');
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'No error message was shown');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$this->assert(isset($view_link), 'The message area contains a link to a term');
}
// Retrieve node object, ensure that the topic was created and in the proper forum.
......@@ -622,7 +630,7 @@ private function verifyForums(EntityInterface $node, $admin, $response = 200) {
$edit['taxonomy_forums'] = $this->rootForum['tid'];
$edit['shadow'] = TRUE;
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit['title[0][value]'])), 'Forum node was edited');
$this->assertText(t('Forum topic @title has been updated.', array('@title' => $edit['title[0][value]'])), 'Forum node was edited');
// Verify topic was moved to a different forum.
$forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
......
......@@ -118,7 +118,11 @@ public function testContentTypeLanguageConfiguration() {
'langcode[0][value]' => 'en',
);
$this->drupalPostForm($path, $edit, t('Save'));
$this->assertRaw(t('%title has been updated.', array('%title' => $node_title)));
$this->assertText(t('@title has been updated.', array('@title' => $node_title)));
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/' . $node->id()));
$this->assert(isset($view_link), 'The message area contains the link to the edited node');
$this->drupalLogout();
}
......
......@@ -356,7 +356,7 @@ public function save(array $form, FormStateInterface $form_state) {
$node->save();
$node_link = $node->link($this->t('View'));
$context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link);
$t_args = array('@type' => node_get_type_label($node), '%title' => $node->label());
$t_args = array('@type' => node_get_type_label($node), '%title' => $node->link($node->label()));
if ($insert) {
$this->logger('content')->notice('@type: added %title.', $context);
......
......@@ -48,7 +48,11 @@ function testNodeCreation() {
$this->drupalPostForm('node/add/page', $edit, t('Save'));
// Check that the Basic page has been created.
$this->assertRaw(t('@post %title has been created.', array('@post' => 'Basic page', '%title' => $edit['title[0][value]'])), 'Basic page created.');
$this->assertText(t('@post @title has been created.', array('@post' => 'Basic page', '@title' => $edit['title[0][value]'])), 'Basic page created.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$this->assert(isset($view_link), 'The message area contains a link to a node');
// Check that the node exists in the database.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
......@@ -137,7 +141,11 @@ function testUnpublishedNodeCreation() {
$this->assertText(t('Test page text'));
// Confirm that the node was created.
$this->assertRaw(t('@post %title has been created.', array('@post' => 'Basic page', '%title' => $edit['title[0][value]'])));
$this->assertText(t('@post @title has been created.', array('@post' => 'Basic page', '@title' => $edit['title[0][value]'])));
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$this->assert(isset($view_link), 'The message area contains a link to a node');
}
/**
......
......@@ -23,12 +23,22 @@ class ShortcutForm extends ContentEntityForm {
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$status = $entity->save();
$url = $entity->getUrl();
// There's an edge case where a user can have permission to
// 'link to any content', but has no right to access the linked page. So we
// check the access before showing the link.
if ($url->access()) {
$view_link = \Drupal::l($entity->getTitle(), $url);
}
else {
$view_link = $entity->getTitle();
}
if ($status == SAVED_UPDATED) {
$message = $this->t('The shortcut %link has been updated.', array('%link' => $entity->getTitle()));
$message = $this->t('The shortcut %link has been updated.', array('%link' => $view_link));
}
else {
$message = $this->t('Added a shortcut for %title.', array('%title' => $entity->getTitle()));
$message = $this->t('Added a shortcut for %title.', array('%title' => $view_link));
}
drupal_set_message($message);
......
......@@ -86,7 +86,11 @@ function testEntityFormLanguage() {
$edit['body[0][value]'] = $this->randomMachineName(16);
$edit['langcode[0][value]'] = $langcode;
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$this->assertRaw(t('Basic page %title has been created.', array('%title' => $edit['title[0][value]'])), 'Basic page created.');
$this->assertText(t('Basic page @title has been created.', array('@title' => $edit['title[0][value]'])), 'Basic page created.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$this->assert(isset($view_link), 'The message area contains a link to a node');
// Check to make sure the node was created.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
......
......@@ -123,15 +123,16 @@ public function save(array $form, FormStateInterface $form_state) {
$result = $term->save();
$link = $term->link($this->t('Edit'), 'edit-form');
$edit_link = $term->link($this->t('Edit'), 'edit-form');
$view_link = $term->link($term->getName());
switch ($result) {
case SAVED_NEW:
drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName())));
$this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => $link));
drupal_set_message($this->t('Created new term %term.', array('%term' => $view_link)));
$this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => $edit_link));
break;
case SAVED_UPDATED:
drupal_set_message($this->t('Updated term %term.', array('%term' => $term->getName())));
$this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => $link));
drupal_set_message($this->t('Updated term %term.', array('%term' => $view_link)));
$this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => $edit_link));
break;
}
......
......@@ -255,7 +255,12 @@ function testNodeTermCreationAndDeletion() {
// Save, creating the terms.
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->assertRaw(t('@type %title has been created.', array('@type' => t('Article'), '%title' => $edit['title[0][value]'])), 'The node was created successfully.');
$this->assertText(t('@type @title has been created.', array('@type' => t('Article'), '@title' => $edit['title[0][value]'])), 'The node was created successfully.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$this->assert(isset($view_link), 'The message area contains a link to a node');
foreach ($terms as $term) {
$this->assertText($term, 'The term was saved and appears on the node page.');
}
......
......@@ -36,7 +36,11 @@ function testVocabularyPermissionsTaxonomyTerm() {
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Created new term %name.', array('%name' => $edit['name[0][value]'])), 'Term created successfully.');
$this->assertText(t('Created new term @name.', array('@name' => $edit['name[0][value]'])), 'Term created successfully.');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$this->assert(isset($view_link), 'The message area contains a link to a term');
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
......@@ -48,7 +52,7 @@ function testVocabularyPermissionsTaxonomyTerm() {
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Updated term %name.', array('%name' => $edit['name[0][value]'])), 'Term updated successfully.');
$this->assertText(t('Updated term @name.', array('@name' => $edit['name[0][value]'])), 'Term updated successfully.');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
......@@ -76,7 +80,11 @@ function testVocabularyPermissionsTaxonomyTerm() {
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Updated term %name.', array('%name' => $edit['name[0][value]'])), 'Term updated successfully.');
$this->assertText(t('Updated term @name.', array('@name' => $edit['name[0][value]'])), 'Term updated successfully.');
// Verify that the update message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment