Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitise hyphens when using pattern id as theme hook #295

Open
wants to merge 3 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Definition/PatternDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public function __construct(array $definition = []) {
$this->id = $this->definition['id'];
$this->setFields($this->definition['fields']);
$this->setVariants($this->definition['variants']);
$this->setThemeHook(self::PATTERN_PREFIX . $this->id());
// As we now allow hyphens in pattern IDs we need to turn them into
// underscores when setting the theme hook.
$hook_friendly_id = str_replace('-', '_', $this->id());
$this->setThemeHook(self::PATTERN_PREFIX . $hook_friendly_id);

if (!empty($definition['theme hook'])) {
$this->setThemeHook($definition['theme hook']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Foo Bar
Foo Bar default template
13 changes: 13 additions & 0 deletions tests/src/Functional/UiPatternsPreviewRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public function testPatternPreviewSuggestions() {
foreach ($suggestions as $suggestion) {
$assert_session->responseContains($suggestion);
}

// Pattern foo-bar default template is loaded.
$assert_session->pageTextContains('Foo Bar default template');
$assert_session->pageTextNotContains('Foo Bar overridden template');

// Install test theme to load template(s) overrides.
$this->container->get('theme_installer')->install(['ui_patterns_theme_test']);
$this->container->get('theme_handler')->setDefault('ui_patterns_theme_test');
$this->container->set('theme.registry', NULL);

$this->drupalGet('/patterns');
$assert_session->pageTextContains('Foo Bar overridden template');
$assert_session->pageTextNotContains('Foo Bar default template');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo Bar overridden template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: 'UI Patterns Test theme'
type: theme
description: 'Theme for testing UI Patterns features in action on a theme.'
core: 8.x