class SkinPluginManager in Skinr 8.2
Manages plugins for configuration translation mappers.
Hierarchy
- class \Drupal\Component\Plugin\PluginManagerBase implements PluginManagerInterface uses DiscoveryTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
- class \Drupal\skinr\SkinPluginManager
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
Expanded class hierarchy of SkinPluginManager
1 string reference to 'SkinPluginManager'
1 service uses SkinPluginManager
File
- src/
SkinPluginManager.php, line 20 - Contains \Drupal\skinr\SkinPluginManager.
Namespace
Drupal\skinrView source
class SkinPluginManager extends DefaultPluginManager {
const PLUGIN_PATH = 'skins';
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* Constructs a new SkinPluginManager.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
*/
public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
}
/**
* {@inheritdoc}
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
// Look at all themes and modules.
// @todo If the list of installed modules and themes is changed, new
// definitions are not picked up immediately and obsolete definitions
// are not removed, because the list of search directories is only
// compiled once in this constructor. The current code only works due to
// coincidence: The request that installs (for instance, a new theme)
// does not instantiate this plugin manager at the beginning of the
// request; when routes are being rebuilt at the end of the request,
// this service only happens to get instantiated with the updated list
// of installed themes.
$directories = array();
foreach ($this->moduleHandler
->getModuleList() as $name => $module) {
$directories[$name] = $module
->getPath() . '/' . self::PLUGIN_PATH;
}
foreach ($this->themeHandler
->listInfo() as $theme) {
$directories[$theme
->getName()] = $theme
->getPath() . '/' . self::PLUGIN_PATH;
}
// Check skins directories for *.yml files in module/theme roots.
$this->discovery = new SkinYamlDirectoryDiscovery($directories, 'skin_plugins', 'id');
$this->discovery
->addTranslatableProperty('title');
// $this->discovery = new InfoHookDecorator($this->discovery, 'skinr_info');
// $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
}
return $this->discovery;
}
/**
* Prepare the default status for a skin.
*
* @param $skin
* Information about a registered skin.
*
* @return array
* An array of default statuses for each enabled theme.
*/
protected function addStatusDefaults($skin) {
$status = array();
// Retrieve the explicit default status of the registering theme for itself.
$base_theme_status = NULL;
if (isset($skin['status'][$skin['source']['name']])) {
$base_theme_status = $skin['status'][$skin['source']['name']];
}
// Retrieve the sub themes of the base theme that registered the skin.
$sub_themes = array();
if (isset($skin['source']['sub themes'])) {
$sub_themes = $skin['source']['sub themes'];
}
$theme_handler = \Drupal::service('theme_handler');
$themes = $theme_handler
->listInfo();
foreach ($themes as $name => $theme) {
if (!$theme->status) {
continue;
}
// If this theme is a sub theme of the theme that registered the skin, check
// whether we need to inherit the status of the base theme to the sub theme.
// This is the case when a skin of a base theme enables itself for the base
// theme (not knowing about potential sub themes).
if (isset($base_theme_status) && isset($sub_themes[$name])) {
$status[$name] = $base_theme_status;
}
// Apply global default.
$status += array(
$name => $skin['default status'],
);
}
// Lastly, apply all explicit defaults.
$status = array_merge($status, $skin['status']);
return $status;
}
/**
* {@inheritdoc}
*/
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
if (!isset($definition['skins']) && !isset($definition['groups'])) {
throw new InvalidPluginDefinitionException($plugin_id, "The plugin definition of the mapper '{$plugin_id}' does not contain any groups or skins.");
}
// Set defaults for groups.
if (!empty($definition['groups'])) {
foreach ($definition['groups'] as &$group) {
$group += [
'title' => t('Untitled'),
'description' => '',
'weight' => 0,
];
}
}
// Set defaults for skins.
if (!empty($definition['skins'])) {
/** @var \Drupal\Core\Extension\Extension $extension */
$extension = $this->moduleHandler
->getModule($definition['provider']);
$extension_info = system_get_info($extension
->getType(), $extension
->getName());
foreach ($definition['skins'] as $skin_name => &$skin) {
$skin += [
'name' => $skin_name,
'type' => 'checkboxes',
'group' => 'general',
'title' => $skin_name,
'description' => '',
'theme hooks' => [],
'attached' => [],
'options' => [],
'default status' => 0,
'status' => [],
'weight' => 0,
'source' => [],
];
// Add source information.
$skin['source'] = [
'type' => 'module',
'name' => $extension
->getName(),
'path' => dirname($definition['path']),
'pathname' => $definition['path'],
'version' => $extension_info['version'],
];
/* @todo
if ($extension->getType() == 'theme') {
$skin['source'] += [
'base themes' => $this->themeHandler->getBaseThemes($this->themeHandler->listInfo(), $extension->getName()),
'sub themes' => isset($sub_themes[$name]) ? $sub_themes[$name] : array(),
];
}
*/
// Merge in default status for all themes.
$skin['status'] = $this
->addStatusDefaults($skin);
// Validate skin options.
foreach ($skin['options'] as $option_name => $option) {
// Validate class by running it through Html::getClass().
if (!is_array($skin['options'][$option_name]['class'])) {
// Raise an error.
\Drupal::logger('skinr')
->warning('The class for option %option in skin %skin needs to be an array.', array(
'%option' => $option_name,
'%skin' => $skin_name,
));
// Reset to array to prevent errors.
$skin['options'][$option_name]['class'] = array();
}
foreach ($skin['options'][$option_name]['class'] as $key => $class) {
$skin['options'][$option_name]['class'][$key] = Html::getClass($class);
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultPluginManager:: |
protected | property | Additional namespaces the annotation discovery mechanism should scan for annotation definitions. | |
DefaultPluginManager:: |
protected | property | Name of the alter hook if one should be invoked. | |
DefaultPluginManager:: |
protected | property | The cache key. | |
DefaultPluginManager:: |
protected | property | An array of cache tags to use for the cached definitions. | |
DefaultPluginManager:: |
protected | property | A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. | 9 |
DefaultPluginManager:: |
protected | property | The module handler to invoke the alter hook. | 1 |
DefaultPluginManager:: |
protected | property | An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations. | |
DefaultPluginManager:: |
protected | property | The name of the annotation that contains the plugin definition. | |
DefaultPluginManager:: |
protected | property | The interface each plugin should implement. | 1 |
DefaultPluginManager:: |
protected | property | The subdirectory within a namespace to look for plugins, or FALSE if the plugins are in the top level of the namespace. | |
DefaultPluginManager:: |
protected | function | Invokes the hook to alter the definitions if the alter hook is set. | 1 |
DefaultPluginManager:: |
protected | function | Sets the alter hook name. | |
DefaultPluginManager:: |
public | function |
Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface:: |
5 |
DefaultPluginManager:: |
protected | function | Extracts the provider from a plugin definition. | |
DefaultPluginManager:: |
protected | function | Finds plugin definitions. | 7 |
DefaultPluginManager:: |
private | function | Fix the definitions of context-aware plugins. | |
DefaultPluginManager:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
protected | function | Returns the cached plugin definitions of the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryTrait:: |
2 |
DefaultPluginManager:: |
protected | function |
Gets the plugin factory. Overrides PluginManagerBase:: |
|
DefaultPluginManager:: |
protected | function | Determines if the provider of a definition exists. | 3 |
DefaultPluginManager:: |
public | function | Initialize the cache backend. | |
DefaultPluginManager:: |
protected | function | Sets a cache of plugin definitions for the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
Disable the use of caches. Overrides CachedDiscoveryInterface:: |
1 |
DiscoveryCachedTrait:: |
protected | property | Cached definitions array. | 1 |
DiscoveryCachedTrait:: |
public | function |
Overrides DiscoveryTrait:: |
3 |
DiscoveryTrait:: |
protected | function | Gets a specific plugin definition. | |
DiscoveryTrait:: |
public | function | ||
PluginManagerBase:: |
protected | property | The object that discovers plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that instantiates plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | |
PluginManagerBase:: |
public | function |
Creates a pre-configured instance of a plugin. Overrides FactoryInterface:: |
12 |
PluginManagerBase:: |
public | function |
Gets a preconfigured instance of a plugin. Overrides MapperInterface:: |
7 |
PluginManagerBase:: |
protected | function | Allows plugin managers to specify custom behavior if a plugin is not found. | 1 |
SkinPluginManager:: |
protected | property | The theme handler. | |
SkinPluginManager:: |
protected | function | Prepare the default status for a skin. | |
SkinPluginManager:: |
protected | function |
Gets the plugin discovery. Overrides DefaultPluginManager:: |
|
SkinPluginManager:: |
constant | |||
SkinPluginManager:: |
public | function |
Performs extra processing on plugin definitions. Overrides DefaultPluginManager:: |
|
SkinPluginManager:: |
public | function |
Constructs a new SkinPluginManager. Overrides DefaultPluginManager:: |
|
UseCacheBackendTrait:: |
protected | property | Cache backend instance. | |
UseCacheBackendTrait:: |
protected | property | Flag whether caches should be used or skipped. | |
UseCacheBackendTrait:: |
protected | function | Fetches from the cache backend, respecting the use caches flag. | 1 |
UseCacheBackendTrait:: |
protected | function | Stores data in the persistent cache, respecting the use caches flag. |