BlockStyleManager.php in Block Style Plugins 8.2
File
src/Plugin/BlockStyleManager.php
View source
<?php
namespace Drupal\block_style_plugins\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator;
use Drupal\Core\Theme\ThemeManagerInterface;
class BlockStyleManager extends DefaultPluginManager {
protected $defaults = [
'class' => 'Drupal\\block_style_plugins\\Plugin\\BlockStyle',
];
protected $themeHandler;
protected $themeManager;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeManagerInterface $theme_manager) {
parent::__construct('Plugin/BlockStyle', $namespaces, $module_handler, 'Drupal\\block_style_plugins\\Plugin\\BlockStyleInterface', 'Drupal\\block_style_plugins\\Annotation\\BlockStyle');
$discovery = $this
->getDiscovery();
$this->discovery = new YamlDiscoveryDecorator($discovery, 'blockstyle', $module_handler
->getModuleDirectories() + $theme_handler
->getThemeDirectories());
$this->themeHandler = $theme_handler;
$this->themeManager = $theme_manager;
$this
->alterInfo('block_style_plugins_info');
$this
->setCacheBackend($cache_backend, 'block_style_plugins');
}
protected function providerExists($provider) {
return $this->moduleHandler
->moduleExists($provider) || $this->themeHandler
->themeExists($provider);
}
protected function alterDefinitions(&$definitions) {
if ($this->alterHook) {
$this->moduleHandler
->alter($this->alterHook, $definitions);
$this->themeManager
->alter($this->alterHook, $definitions);
}
}
public function getBlockDefinitions() {
$definitions = $this
->getDefinitions();
$block_definitions = array_filter($definitions, function ($def) {
return empty($def['type']) || $def['type'] == 'block' || $def['type'] == 'all';
});
return $block_definitions;
}
public function getSectionDefinitions() {
$definitions = $this
->getDefinitions();
$section_definitions = array_filter($definitions, function ($def) {
return isset($def['type']) && ($def['type'] == 'section' || $def['type'] == 'all');
});
return $section_definitions;
}
}