Verified Commit 0f2bebf2 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2861840 by tim.plunkett, lauriii: Preprocess functions are not merged...

Issue #2861840 by tim.plunkett, lauriii: Preprocess functions are not merged when a module registers a theme hook for a theme-provided template
parent 71584842
Loading
Loading
Loading
Loading
+10 −1
Changes for core/lib/Drupal/Core/Theme/Registry.php: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Core\Theme;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DestructableInterface;
@@ -565,10 +566,18 @@ protected function processExtension(array &$cache, $name, $type, $theme, $path)
          $info['preprocess functions'] = array_merge($cache[$hook]['preprocess functions'], $info['preprocess functions']);
        }
        $result[$hook]['preprocess functions'] = $info['preprocess functions'];

        // If a theme implementation definition provides both 'template' and
        // 'function', the 'function' will be used. In this case, if the new
        // result provides a 'template' value, any existing 'function' value
        // must be removed for the override to be called.
        if (isset($result[$hook]['template'])) {
          unset($cache[$hook]['function']);
        }
      }

      // Merge the newly created theme hooks into the existing cache.
      $cache = $result + $cache;
      $cache = NestedArray::mergeDeep($cache, $result);
    }

    // Let themes have variable preprocessors even if they didn't register a
+11 −0
Changes for core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -33,6 +33,17 @@ protected function setUp() {
    $this->layoutPluginManager = $this->container->get('plugin.manager.core.layout');
  }

  /**
   * Tests that a layout provided by a theme has the preprocess function set.
   */
  public function testThemeProvidedLayout() {
    $this->container->get('theme_installer')->install(['test_layout_theme']);
    $this->config('system.theme')->set('default', 'test_layout_theme')->save();

    $theme_definitions = $this->container->get('theme.registry')->get();
    $this->assertTrue(in_array('template_preprocess_layout', $theme_definitions['test_layout_theme']['preprocess functions']));
  }

  /**
   * Test rendering a layout.
   *
+1 −0
Changes for core/modules/layout_discovery/tests/themes/test_layout_theme/templates/test-layout-theme.html.twig: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
{{ content.content }}
+6 −0
Changes for core/modules/layout_discovery/tests/themes/test_layout_theme/test_layout_theme.info.yml: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: 'Test layout theme'
type: theme
description: 'Theme for testing a theme-provided layout'
version: VERSION
base theme: classy
core: 8.x
+7 −0
Changes for core/modules/layout_discovery/tests/themes/test_layout_theme/test_layout_theme.layouts.yml: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
test_layout_theme:
  label: 'Test Layout - Theme'
  category: 'Test Layout Theme'
  template: templates/test-layout-theme
  regions:
    content:
      label: Content
Loading