Commit 2b74c933 authored by catch's avatar catch
Browse files

Issue #2754929 by joelpittet, markcarver: Internal path(s) missing for "html"...

Issue #2754929 by joelpittet, markcarver: Internal path(s) missing for "html" and "page" theme hook suggestions on <front>
parent 2bccef8b
......@@ -251,12 +251,7 @@ function system_hook_info() {
* Implements hook_theme_suggestions_HOOK().
*/
function system_theme_suggestions_html(array $variables) {
if (\Drupal::service('path.matcher')->isFrontPage()) {
$path_args = [''];
}
else {
$path_args = explode('/', ltrim(\Drupal::service('path.current')->getPath(), '/'));
}
$path_args = explode('/', trim(\Drupal::service('path.current')->getPath(), '/'));
return theme_get_suggestions($path_args, 'html');
}
......@@ -264,12 +259,7 @@ function system_theme_suggestions_html(array $variables) {
* Implements hook_theme_suggestions_HOOK().
*/
function system_theme_suggestions_page(array $variables) {
if (\Drupal::service('path.matcher')->isFrontPage()) {
$path_args = [''];
}
else {
$path_args = explode('/', Url::fromRoute('<current>')->getInternalPath());
}
$path_args = explode('/', trim(\Drupal::service('path.current')->getPath(), '/'));
return theme_get_suggestions($path_args, 'page');
}
......
......@@ -2,6 +2,8 @@
namespace Drupal\KernelTests\Core\Theme;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Theme\Registry;
use Drupal\Core\Utility\ThemeRegistry;
use Drupal\KernelTests\KernelTestBase;
......@@ -157,4 +159,37 @@ public function testThemeRegistryAlterByTheme() {
$this->assertEqual('value', $registry->get()['theme_test_template_test']['variables']['additional']);
}
/**
* Tests front node theme suggestion generation.
*/
public function testThemeSuggestions() {
// Mock the current page as the front page.
/** @var PathMatcherInterface $path_matcher */
$path_matcher = $this->prophesize(PathMatcherInterface::class);
$path_matcher->isFrontPage()->willReturn(TRUE);
$this->container->set('path.matcher', $path_matcher->reveal());
/** @var CurrentPathStack $path_matcher */
$path_current = $this->prophesize(CurrentPathStack::class);
$path_current->getPath()->willReturn('/node/1');
$this->container->set('path.current', $path_current->reveal());
// Check suggestions provided through hook_theme_suggestions_html().
$suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_html', [[]]);
$this->assertSame([
'html__node',
'html__node__%',
'html__node__1',
'html__front',
], $suggestions, 'Found expected html node suggestions.');
// Check suggestions provided through hook_theme_suggestions_page().
$suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_page', [[]]);
$this->assertSame([
'page__node',
'page__node__%',
'page__node__1',
'page__front',
], $suggestions, 'Found expected page node suggestions.');
}
}
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