class LibraryPattern in UI Patterns 8
The UI Pattern plugin.
ID is set to "yaml" for backward compatibility reasons.
Plugin annotation
@UiPattern(
id = "yaml",
label = @Translation("Library Pattern"),
description = @Translation("Pattern defined using a YAML file."),
deriver = "\Drupal\ui_patterns_library\Plugin\Deriver\LibraryDeriver"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\ui_patterns\Plugin\PatternBase implements ContainerFactoryPluginInterface, PatternInterface
- class \Drupal\ui_patterns_library\Plugin\UiPatterns\Pattern\LibraryPattern
- class \Drupal\ui_patterns\Plugin\PatternBase implements ContainerFactoryPluginInterface, PatternInterface
Expanded class hierarchy of LibraryPattern
File
- modules/
ui_patterns_library/ src/ Plugin/ UiPatterns/ Pattern/ LibraryPattern.php, line 23
Namespace
Drupal\ui_patterns_library\Plugin\UiPatterns\PatternView source
class LibraryPattern extends PatternBase {
/**
* Theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* UiPatternsManager constructor.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, $root, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $root, $module_handler);
$this->themeHandler = $theme_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('app.root'), $container
->get('module_handler'), $container
->get('theme_handler'));
}
/**
* {@inheritdoc}
*/
public function getThemeImplementation() {
$item = parent::getThemeImplementation();
$definition = $this
->getPluginDefinition();
$item[$definition['theme hook']] += $this
->processTemplateProperty($definition);
$item[$definition['theme hook']] += $this
->processCustomThemeHookProperty($definition);
return $item;
}
/**
* Process 'custom hook theme' definition property.
*
* @param \Drupal\ui_patterns\Definition\PatternDefinition $definition
* Pattern definition array.
*
* @return array
* Processed hook definition portion.
*/
protected function processCustomThemeHookProperty(PatternDefinition $definition) {
/** @var \Drupal\Core\Extension\Extension $module */
$return = [];
if (!$definition
->hasCustomThemeHook() && $this->moduleHandler
->moduleExists($definition
->getProvider())) {
$module = $this->moduleHandler
->getModule($definition
->getProvider());
$return['path'] = $module
->getPath() . '/templates';
if ($this
->templateExists($definition
->getBasePath(), $definition
->getTemplate())) {
$return['path'] = str_replace($this->root, '', $definition
->getBasePath());
}
}
return $return;
}
/**
* Weather template exists in given directory.
*
* @param string $directory
* Directory full path.
* @param string $template
* Template name, without default Twig extension.
*
* @return bool
* Weather template exists in given directory.
*/
protected function templateExists($directory, $template) {
return file_exists($directory . DIRECTORY_SEPARATOR . $template . '.html.twig');
}
/**
* Process 'template' definition property.
*
* @param \Drupal\ui_patterns\Definition\PatternDefinition $definition
* Pattern definition array.
*
* @return array
* Processed hook definition portion.
*/
protected function processTemplateProperty(PatternDefinition $definition) {
$return = [];
if ($definition
->hasTemplate()) {
$return = [
'template' => $definition
->getTemplate(),
];
}
return $return;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LibraryPattern:: |
protected | property | Theme handler. | |
LibraryPattern:: |
public static | function |
Creates an instance of the plugin. Overrides PatternBase:: |
|
LibraryPattern:: |
public | function |
Get theme implementation for current pattern. Overrides PatternBase:: |
|
LibraryPattern:: |
protected | function | Process 'custom hook theme' definition property. | |
LibraryPattern:: |
protected | function | Process 'template' definition property. | |
LibraryPattern:: |
protected | function | Weather template exists in given directory. | |
LibraryPattern:: |
public | function |
UiPatternsManager constructor. Overrides PatternBase:: |
|
PatternBase:: |
protected | property | Module handler. | |
PatternBase:: |
protected | property | The app root. | |
PatternBase:: |
public | function |
Get library definitions for current pattern. Overrides PatternInterface:: |
|
PatternBase:: |
protected | function | Process libraries. | |
PatternBase:: |
protected | function | Process 'use' definition property. | |
PatternBase:: |
protected | function | Process theme variables. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |