diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 3cae04532e..5f19b1328c 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -15,6 +15,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\Element\Textfield; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Component\Utility\Xss; /** * Implements hook_help(). @@ -300,8 +301,8 @@ function template_preprocess_color_scheme_form(&$variables) { } // Attempt to load preview HTML if the theme provides it. - $preview_html_path = \Drupal::root() . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html'); - $variables['html_preview']['#markup'] = file_get_contents($preview_html_path); + $preview_html_path = isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html.twig'; + $variables['html_preview']['#markup'] = \Drupal::service('twig')->loadTemplate($preview_html_path, NULL)->render(array()); } /** diff --git a/core/modules/color/preview.html b/core/modules/color/preview.html deleted file mode 100644 index d89edcb0d0..0000000000 --- a/core/modules/color/preview.html +++ /dev/null @@ -1,7 +0,0 @@ -
-
-

Lorem ipsum dolor

-

Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

-
-
-
diff --git a/core/modules/color/preview.html.twig b/core/modules/color/preview.html.twig new file mode 100644 index 0000000000..2e1be5937d --- /dev/null +++ b/core/modules/color/preview.html.twig @@ -0,0 +1,11 @@ +
+
+

+ {% trans %} Example heading {% endtrans %} +

+

+ {% trans %} This is a block of example content. This content is here to demonstrate what actual content would look like in the color scheme you configure. This is an example link, is is here to demonstrate how background colors you configure may affect the readability of links. This is some more text to demonstrate what actual content would look like in the color scheme you configure. {% endtrans %} +

+
+
+
diff --git a/core/modules/contact/src/MessageViewBuilder.php b/core/modules/contact/src/MessageViewBuilder.php index 3024f62912..ffdb0bdd89 100644 --- a/core/modules/contact/src/MessageViewBuilder.php +++ b/core/modules/contact/src/MessageViewBuilder.php @@ -26,25 +26,6 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode) { /** * {@inheritdoc} */ - public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { - parent::buildComponents($build, $entities, $displays, $view_mode); - - foreach ($entities as $id => $entity) { - // Add the message extra field, if enabled. - $display = $displays[$entity->bundle()]; - if ($entity->getMessage() && $display->getComponent('message')) { - $build[$id]['message'] = array( - '#type' => 'item', - '#title' => t('Message'), - '#plain_text' => $entity->getMessage(), - ); - } - } - } - - /** - * {@inheritdoc} - */ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) { $build = parent::view($entity, $view_mode, $langcode); diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index ffc2e9091c..9ffd3af43c 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -49,6 +49,7 @@ function testSiteWideContact() { 'administer contact forms', 'administer users', 'administer account settings', + 'administer contact_message display', 'administer contact_message fields', 'administer contact_message form display', ]); @@ -293,11 +294,11 @@ function testSiteWideContact() { $this->assertText($field_label); // Submit the contact form and verify the content. - $edit = array( + $edit = [ 'subject[0][value]' => $this->randomMachineName(), 'message[0][value]' => $this->randomMachineName(), $field_name . '[0][value]' => $this->randomMachineName(), - ); + ]; $this->drupalPostForm(NULL, $edit, t('Send message')); $mails = $this->drupalGetMails(); $mail = array_pop($mails); @@ -315,11 +316,11 @@ function testSiteWideContact() { $this->drupalGet('contact/' . $contact_form); // Submit the contact form and verify the content. - $edit = array( + $edit = [ 'subject[0][value]' => $this->randomMachineName(), 'message[0][value]' => $this->randomMachineName(), $field_name . '[0][value]' => $this->randomMachineName(), - ); + ]; $this->drupalPostForm(NULL, $edit, t('Send message')); $this->assertText('Thanks for your submission.'); $this->assertUrl('user/' . $admin_user->id()); @@ -335,15 +336,41 @@ function testSiteWideContact() { $this->drupalGet('contact/' . $contact_form); // Submit the contact form and verify the content. - $edit = array( + $edit = [ 'subject[0][value]' => $this->randomMachineName(), 'message[0][value]' => $this->randomMachineName(), $field_name . '[0][value]' => $this->randomMachineName(), - ); + ]; $this->drupalPostForm(NULL, $edit, t('Send message')); $result = $this->xpath('//div[@role=:role]', array(':role' => 'contentinfo')); $this->assertEqual(count($result), 0, 'Messages not found.'); $this->assertUrl('user/' . $admin_user->id()); + + // Test preview and visibility of the message field and label. + // Submit the contact form and verify the content. + $edit = [ + 'subject[0][value]' => $this->randomMachineName(), + 'message[0][value]' => $this->randomMachineName(), + $field_name . '[0][value]' => $this->randomMachineName(), + ]; + $this->drupalPostForm('contact/' . $contact_form, $edit, t('Preview')); + // Message is now by default displayed twice, once for the form element and + // once for the viewed message. + $this->assertNoUniqueText(t('Message')); + $this->assertRaw('class="field field--name-message field--type-string-long field--label-above'); + $this->assertText($edit['message[0][value]']); + + // Hide the message field label. + $display_edit = [ + 'fields[message][label]' => 'hidden', + ]; + $this->drupalPostForm('admin/structure/contact/manage/' . $contact_form . '/display', $display_edit, t('Save')); + + $this->drupalPostForm($form->toUrl() . $contact_form, $edit, t('Preview')); + // Message should only be displayed once now. + $this->assertUniqueText(t('Message')); + $this->assertRaw('class="field field--name-message field--type-string-long field--label-hidden field__item">'); + $this->assertText($edit['message[0][value]']); } /** diff --git a/core/themes/bartik/color/color.inc b/core/themes/bartik/color/color.inc index 4f42620d9c..a25f36c3f4 100644 --- a/core/themes/bartik/color/color.inc +++ b/core/themes/bartik/color/color.inc @@ -116,7 +116,7 @@ // Preview files. 'preview_library' => 'bartik/color.preview', - 'preview_html' => 'color/preview.html', + 'preview_html' => 'color/preview.html.twig', // Attachments. '#attached' => [ diff --git a/core/themes/bartik/color/preview.html b/core/themes/bartik/color/preview.html deleted file mode 100644 index 7031b08945..0000000000 --- a/core/themes/bartik/color/preview.html +++ /dev/null @@ -1,65 +0,0 @@ -
- -
- -
Bartik
- -
- -
-
-
-

Etiam est risus

-
- Maecenas id porttitor Ut enim ad minim veniam, quis nostrudfelis. - Laboris nisi ut aliquip ex ea. -
-
-
-
-

Lorem ipsum dolor

-
-
- Sit amet, consectetur adipisicing elit, sed do eiusmod tempor - incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis - nostrud exercitation ullamco laboris nisi ut aliquip ex ea - commodo consequat. Maecenas id porttitor Ut enim ad minim veniam, quis nostr udfelis. -
-
-
-
- - - -
diff --git a/core/themes/bartik/color/preview.html.twig b/core/themes/bartik/color/preview.html.twig new file mode 100644 index 0000000000..3917f54e58 --- /dev/null +++ b/core/themes/bartik/color/preview.html.twig @@ -0,0 +1,67 @@ +
+ +
+ +
{% trans %} Bartik {% endtrans %}
+ +
+ +
+
+
+

{% trans %} Example heading {% endtrans %}

+
+ {% trans %} This is a block of example content. This content is here to demonstrate what actual content would look like + in the color scheme you configure. {% endtrans %} +
+
+
+
+

{% trans %} This is an example heading {% endtrans %}

+
+
+ {% trans %} This is a block of example content. This content is here to demonstrate what actual content would look like + in the color scheme you configure. This is an example link, is here to demonstrate + how background colors you configure may affect the readability of links. This is another sentence to demonstrate + what actual content would look like in the color scheme you configure. This is another example link. + This is the end of this block of example content. {% endtrans %} +
+
+
+
+ + + +