Skip to content
Snippets Groups Projects
Commit d0a83b88 authored by Antonio De Marco's avatar Antonio De Marco
Browse files

Add preview theme suggestions.

parent 670d63d8
Branches
Tags
No related merge requests found
foo:
label: Foo
variants:
default:
label: Default
<?php
namespace Drupal\Tests\ui_patterns\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\ui_patterns\Traits\TwigDebugTrait;
/**
* Test pattern preview rendering.
*
* @group ui_patterns
*/
class UiPatternsPreviewRenderTest extends WebDriverTestBase {
/**
* Disable schema validation when running tests.
*
* @var bool
*
* @todo: Fix this by providing actual schema validation.
*/
protected $strictConfigSchema = FALSE;
use TwigDebugTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'ui_patterns',
'ui_patterns_library',
'ui_patterns_render_test',
];
/**
* Tests pattern preview suggestions.
*/
public function testPatternPreviewSuggestions() {
$assert_session = $this->assertSession();
$this->enableTwigDebugMode();
$user = $this->drupalCreateUser([], NULL, TRUE);
$this->drupalLogin($user);
$this->drupalGet('/patterns');
// Assert correct variant suggestions.
$suggestions = [
'pattern-foo--variant-default--preview.html.twig',
'pattern-foo--variant-default.html.twig',
'pattern-foo--preview.html.twig',
'pattern-foo.html.twig',
];
foreach ($suggestions as $suggestion) {
$assert_session->responseContains($suggestion);
}
}
}
......@@ -60,7 +60,17 @@ function ui_patterns_theme_suggestions_alter(array &$suggestions, array $variabl
* Implements hook_ui_patterns_suggestions_alter().
*/
function ui_patterns_ui_patterns_suggestions_alter(array &$suggestions, array $variables, PatternContext $context) {
// Add preview theme suggestion.
if ($context->isOfType('preview')) {
$suggestions[] = $variables['theme_hook_original'] . '__preview';
}
if (!empty($variables['variant'])) {
$suggestions[] = $variables['theme_hook_original'] . '__variant_' . $variables['variant'];
// Add variant preview theme suggestion.
if ($context->isOfType('preview')) {
$suggestions[] = $variables['theme_hook_original'] . '__variant_' . $variables['variant'] . '__preview';
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment