SocialMediaLinksIconsetManager.php in Social Media Links Block and Field 8.2
File
src/SocialMediaLinksIconsetManager.php
View source
<?php
namespace Drupal\social_media_links;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
class SocialMediaLinksIconsetManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/SocialMediaLinks/Iconset', $namespaces, $module_handler, 'Drupal\\social_media_links\\IconsetInterface', 'Drupal\\social_media_links\\Annotation\\Iconset');
$this
->alterInfo('social_media_links_iconset_info');
$this
->setCacheBackend($cache_backend, 'social_media_links_iconsets');
}
public function getIconsets() {
$plugins = $this
->getDefinitions();
foreach ($plugins as $plugin_id => $plugin) {
$instance = $this
->createInstance($plugin_id);
if ($instance instanceof IconsetInterface) {
$plugins[$plugin_id]['instance'] = $instance;
}
else {
$plugins[$plugin_id] = [];
}
}
return $plugins;
}
public function getStyles() {
$options = [];
foreach ($this
->getIconsets() as $iconset_id => $iconset) {
if ($iconset['instance']
->getPath()) {
$styles = $iconset['instance']
->getStyle();
foreach ($styles as $key => $style) {
$options[$iconset_id][$iconset_id . ':' . $key] = $style;
}
}
else {
$options[$iconset_id] = [];
}
}
return $options;
}
}