ui_patterns.module in UI Patterns 8
Contains ui_patterns.module.
File
ui_patterns.moduleView source
<?php
/**
* @file
* Contains ui_patterns.module.
*/
use Drupal\ui_patterns\UiPatterns;
use Drupal\ui_patterns\Element\PatternContext;
/**
* Implements hook_theme().
*/
function ui_patterns_theme() {
/** @var \Drupal\ui_patterns\Plugin\PatternBase $pattern */
$items = [
'patterns_destination' => [
'variables' => [
'sources' => NULL,
'context' => NULL,
],
],
'patterns_use_wrapper' => [
'variables' => [
'use' => NULL,
],
],
];
foreach (UiPatterns::getManager()
->getPatterns() as $pattern) {
$items += $pattern
->getThemeImplementation();
}
return $items;
}
/**
* Implements hook_library_info_build().
*/
function ui_patterns_library_info_build() {
/** @var \Drupal\ui_patterns\Plugin\PatternBase $pattern */
$definitions = [];
foreach (UiPatterns::getManager()
->getPatterns() as $pattern) {
$definitions += $pattern
->getLibraryDefinitions();
}
return $definitions;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function ui_patterns_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
if (UiPatterns::getManager()
->isPatternHook($hook)) {
\Drupal::moduleHandler()
->alter('ui_patterns_suggestions', $suggestions, $variables, $variables['context']);
\Drupal::theme()
->alter('ui_patterns_suggestions', $suggestions, $variables, $variables['context']);
}
if ($hook == 'patterns_destination') {
\Drupal::moduleHandler()
->alter('ui_patterns_destination_suggestions', $suggestions, $variables, $variables['context']);
\Drupal::theme()
->alter('ui_patterns_destination_suggestions', $suggestions, $variables, $variables['context']);
}
}
/**
* 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';
}
}
}
Functions
Name | Description |
---|---|
ui_patterns_library_info_build | Implements hook_library_info_build(). |
ui_patterns_theme | Implements hook_theme(). |
ui_patterns_theme_suggestions_alter | Implements hook_theme_suggestions_HOOK_alter(). |
ui_patterns_ui_patterns_suggestions_alter | Implements hook_ui_patterns_suggestions_alter(). |