diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 20d099a..ff37e2b 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -300,8 +300,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([]); } /** diff --git a/core/modules/color/preview.html b/core/modules/color/preview.html deleted file mode 100644 index d89edcb..0000000 --- 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 0000000..eac40f3 --- /dev/null +++ b/core/modules/color/preview.html.twig @@ -0,0 +1,16 @@ +
+
+

+ {% 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, 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/color/tests/modules/color_test/themes/color_test_theme/color/color.inc b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/color.inc index ee77a5a..9f190b3 100644 --- a/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/color.inc +++ b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/color.inc @@ -29,5 +29,5 @@ 'css' => [ 'css/colors.css', ], - 'preview_html' => 'color/preview.html', + 'preview_html' => 'color/preview.html.twig', ]; diff --git a/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html deleted file mode 100644 index f7346ca..0000000 --- a/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html +++ /dev/null @@ -1,8 +0,0 @@ -
-
-

TEST COLOR PREVIEW

-

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/tests/modules/color_test/themes/color_test_theme/color/preview.html.twig b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html.twig new file mode 100644 index 0000000..7753304 --- /dev/null +++ b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html.twig @@ -0,0 +1,14 @@ +
+
+

{% trans %}TEST COLOR PREVIEW{% endtrans %}

+

{% trans %}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.{% endtrans %}

+
+
+
+ diff --git a/core/modules/color/tests/src/Functional/ColorSafePreviewTest.php b/core/modules/color/tests/src/Functional/ColorSafePreviewTest.php index 9f6914c..2cf5951 100644 --- a/core/modules/color/tests/src/Functional/ColorSafePreviewTest.php +++ b/core/modules/color/tests/src/Functional/ColorSafePreviewTest.php @@ -44,10 +44,11 @@ public function testColorPreview() { \Drupal::service('theme_handler')->install(['color_test_theme']); $this->drupalLogin($this->bigUser); - // Markup is being printed from a HTML file located in: - // core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html + // Markup is being printed from a Twig file located in: + // core/modules/color/tests/modules/color_test/themes/color_test_theme/color/preview.html.twig $url = Url::fromRoute('system.theme_settings_theme', ['theme' => 'color_test_theme']); $this->drupalGet($url); + $this->assertText('TEST COLOR PREVIEW'); $this->assertNoRaw(''); diff --git a/core/modules/color/tests/src/Functional/ColorTranslationPreviewTest.php b/core/modules/color/tests/src/Functional/ColorTranslationPreviewTest.php new file mode 100644 index 0000000..e70d2e8 --- /dev/null +++ b/core/modules/color/tests/src/Functional/ColorTranslationPreviewTest.php @@ -0,0 +1,61 @@ +storage = $this->container->get('locale.storage'); + + // Add French language. + ConfigurableLanguage::createFromLangcode('fr')->save(); + + // Installing bartik theme. + \Drupal::service('theme_installer')->install(['bartik']); + } + + /** + * Ensuring the the text in the preview.html.twig file is wrapped with trans tag. + */ + public function testTranslationPreview() { + $account = $this->drupalCreateUser(['administer languages', 'administer themes']); + $this->drupalLogin($account); + + $source = $this->storage->createString([ + 'source' => 'Example heading', + 'context' => '', + ])->save(); + $this->storage->createTranslation([ + 'lid' => $source->lid, + 'language' => 'fr', + 'translation' => 'Exemple de titre', + ])->save(); + + // Checking the string 'Example heading' is translating to French. + $this->drupalGet('fr/admin/appearance/settings/bartik'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('Exemple de titre'); + + } + +} \ No newline at end of file diff --git a/core/themes/bartik/color/color.inc b/core/themes/bartik/color/color.inc index 55464f2..c90f589 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 7031b08..0000000 --- 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 0000000..f4d62b5 --- /dev/null +++ b/core/themes/bartik/color/preview.html.twig @@ -0,0 +1,78 @@ +
+ +
+ +
Bartik
+ +
+ +
+
+
+

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

+
+ {% trans %}This content is here to demonstrate what actual content would + look like in the color scheme you configure. This is a block of example + content.{% 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, to demonstrate how + background colors you configure may affect the readability of links. + 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 %} +

+
+
+
+
+ + + +