Skip to content
Snippets Groups Projects
Verified Commit f2ba76f1 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3420709 by gorkagr, ressa, Ruturaj Chaubey, larowlan, alexpott: Make it...

Issue #3420709 by gorkagr, ressa, Ruturaj Chaubey, larowlan, alexpott: Make it more obvious that a Twig template is overridden
parent 6923b1a6
No related branches found
No related tags found
30 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #107336 canceled
Pipeline: drupal

#107339

    ...@@ -55,18 +55,18 @@ public function testTwigDebugMarkup() { ...@@ -55,18 +55,18 @@ public function testTwigDebugMarkup() {
    $output = (string) $renderer->renderRoot($build); $output = (string) $renderer->renderRoot($build);
    $this->assertStringContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup found in theme output when debug is enabled.'); $this->assertStringContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup found in theme output when debug is enabled.');
    $this->assertStringContainsString("THEME HOOK: 'node'", $output, 'Theme call information found.'); $this->assertStringContainsString("THEME HOOK: 'node'", $output, 'Theme call information found.');
    $this->assertStringContainsString('* node--1--full' . $extension . PHP_EOL . ' x node--1' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' * node' . $extension, $output, 'Suggested template files found in order and node ID specific template shown as current template.'); $this->assertStringContainsString('▪️ node--1--full' . $extension . PHP_EOL . ' node--1' . $extension . PHP_EOL . ' ▪️ node--page--full' . $extension . PHP_EOL . ' ▪️ node--page' . $extension . PHP_EOL . ' ▪️ node--full' . $extension . PHP_EOL . ' ▪️ node' . $extension, $output, 'Suggested template files found in order and node ID specific template shown as current template.');
    $this->assertStringContainsString(Html::escape('node--<script type="text/javascript">alert(\'yo\');</script>'), (string) $output); $this->assertStringContainsString(Html::escape('node--<script type="text/javascript">alert(\'yo\');</script>'), (string) $output);
    $this->assertStringContainsString('<!-- INVALID FILE NAME SUGGESTIONS:' . PHP_EOL . ' See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme_suggestions_alter' . PHP_EOL . ' invalid_theme_suggestions' . PHP_EOL . '-->', $output, 'Twig debug markup found invalid suggestions.'); $this->assertStringContainsString('<!-- INVALID FILE NAME SUGGESTIONS:' . PHP_EOL . ' See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme_suggestions_alter' . PHP_EOL . ' invalid_theme_suggestions' . PHP_EOL . '-->', $output, 'Twig debug markup found invalid suggestions.');
    $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension; $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension;
    $this->assertStringContainsString("BEGIN OUTPUT from '$template_filename'", $output, 'Full path to current template file found.'); $this->assertStringContainsString("💡 BEGIN CUSTOM TEMPLATE OUTPUT from '$template_filename'", $output, 'Full path to current template file found.');
    // Create another node and make sure the template suggestions shown in the // Create another node and make sure the template suggestions shown in the
    // debug markup are correct. // debug markup are correct.
    $node2 = $this->drupalCreateNode(); $node2 = $this->drupalCreateNode();
    $build = $builder->view($node2); $build = $builder->view($node2);
    $output = (string) $renderer->renderRoot($build); $output = (string) $renderer->renderRoot($build);
    $this->assertStringContainsString('* node--2--full' . $extension . PHP_EOL . ' * node--2' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.'); $this->assertStringContainsString('▪️ node--2--full' . $extension . PHP_EOL . ' ▪️ node--2' . $extension . PHP_EOL . ' ▪️ node--page--full' . $extension . PHP_EOL . ' ▪️ node--page' . $extension . PHP_EOL . ' ▪️ node--full' . $extension . PHP_EOL . ' node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.');
    // Create another node and make sure the template suggestions shown in the // Create another node and make sure the template suggestions shown in the
    // debug markup are correct. // debug markup are correct.
    ...@@ -75,7 +75,7 @@ public function testTwigDebugMarkup() { ...@@ -75,7 +75,7 @@ public function testTwigDebugMarkup() {
    $build += $builder->view($node3); $build += $builder->view($node3);
    $output = (string) $renderer->renderRoot($build); $output = (string) $renderer->renderRoot($build);
    $this->assertStringContainsString("THEME HOOK: 'node__foo__bar'", $output, 'Theme call information found.'); $this->assertStringContainsString("THEME HOOK: 'node__foo__bar'", $output, 'Theme call information found.');
    $this->assertStringContainsString('* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $extension . PHP_EOL . ' * node--3--full' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.'); $this->assertStringContainsString('▪️ node--foo--bar' . $extension . PHP_EOL . ' ▪️ node--foo' . $extension . PHP_EOL . ' ▪️ node--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $extension . PHP_EOL . ' ▪️ node--3--full' . $extension . PHP_EOL . ' ▪️ node--3' . $extension . PHP_EOL . ' ▪️ node--page--full' . $extension . PHP_EOL . ' ▪️ node--page' . $extension . PHP_EOL . ' ▪️ node--full' . $extension . PHP_EOL . ' node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.');
    // Disable debug, rebuild the service container, and clear all caches. // Disable debug, rebuild the service container, and clear all caches.
    $parameters = $this->container->getParameter('twig.config'); $parameters = $this->container->getParameter('twig.config');
    ......
    ...@@ -57,11 +57,11 @@ public function testThemeSuggestionsContainerAlter() { ...@@ -57,11 +57,11 @@ public function testThemeSuggestionsContainerAlter() {
    $output = $this->render($build); $output = $this->render($build);
    $extension = '.html.twig'; $extension = '.html.twig';
    $expected = '<!-- FILE NAME SUGGESTIONS:' . PHP_EOL $expected = '<!-- FILE NAME SUGGESTIONS:' . PHP_EOL
    . ' * container--more-link--test-page-display--default' . $extension . PHP_EOL . ' ▪️ container--more-link--test-page-display--default' . $extension . PHP_EOL
    . ' * container--more-link--default' . $extension . PHP_EOL . ' ▪️ container--more-link--default' . $extension . PHP_EOL
    . ' * container--more-link--test-page-display' . $extension . PHP_EOL . ' ▪️ container--more-link--test-page-display' . $extension . PHP_EOL
    . ' * container--more-link' . $extension . PHP_EOL . ' ▪️ container--more-link' . $extension . PHP_EOL
    . ' x container' . $extension . PHP_EOL . ' container' . $extension . PHP_EOL
    . '-->' . PHP_EOL; . '-->' . PHP_EOL;
    $this->assertStringContainsString($expected, $output, 'Views more link container suggestions found in Twig debug output'); $this->assertStringContainsString($expected, $output, 'Views more link container suggestions found in Twig debug output');
    } }
    ......
    ...@@ -89,7 +89,7 @@ function twig_render_template($template_file, array $variables) { ...@@ -89,7 +89,7 @@ function twig_render_template($template_file, array $variables) {
    continue; continue;
    } }
    $template = strtr($suggestion, '_', '-') . $extension; $template = strtr($suggestion, '_', '-') . $extension;
    $prefix = ($template == $current_template) ? 'x' : '*'; $prefix = ($template == $current_template) ? '' : '▪️';
    $suggestion = $prefix . ' ' . $template; $suggestion = $prefix . ' ' . $template;
    } }
    $output['debug_info'] .= "\n<!-- FILE NAME SUGGESTIONS:\n " . Html::escape(implode("\n ", $suggestions)) . "\n-->"; $output['debug_info'] .= "\n<!-- FILE NAME SUGGESTIONS:\n " . Html::escape(implode("\n ", $suggestions)) . "\n-->";
    ...@@ -101,8 +101,15 @@ function twig_render_template($template_file, array $variables) { ...@@ -101,8 +101,15 @@ function twig_render_template($template_file, array $variables) {
    $output['debug_info'] .= "\n-->"; $output['debug_info'] .= "\n-->";
    } }
    } }
    $output['debug_info'] .= "\n<!-- BEGIN OUTPUT from '" . Html::escape($template_file) . "' -->\n"; // Check if the template_file belongs to a custom theme
    $output['debug_suffix'] .= "\n<!-- END OUTPUT from '" . Html::escape($template_file) . "' -->\n\n"; $template_override_status_output = "BEGIN OUTPUT";
    $template_override_suffix_output = "END OUTPUT";
    if (str_starts_with($template_file, $variables['directory'])) {
    $template_override_status_output = "💡 BEGIN CUSTOM TEMPLATE OUTPUT";
    $template_override_suffix_output = "END CUSTOM TEMPLATE OUTPUT";
    }
    $output['debug_info'] .= "\n<!-- " . $template_override_status_output . " from '" . Html::escape($template_file) . "' -->\n";
    $output['debug_suffix'] .= "\n<!-- " . $template_override_suffix_output . " from '" . Html::escape($template_file) . "' -->\n\n";
    } }
    // This output has already been rendered and is therefore considered safe. // This output has already been rendered and is therefore considered safe.
    return Markup::create(implode('', $output)); return Markup::create(implode('', $output));
    ......
    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