Mercurial > hg > isophonics-drupal-site
comparison modules/contrib/views_slideshow/src/ViewsSlideshowWidgetPluginManager.php @ 5:c69a71b4f40f
Add slideshow module
author | Chris Cannam |
---|---|
date | Thu, 07 Dec 2017 14:46:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:8948ab6c87d2 | 5:c69a71b4f40f |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\views_slideshow; | |
4 | |
5 use Drupal\Core\Cache\CacheBackendInterface; | |
6 use Drupal\Core\Extension\ModuleHandlerInterface; | |
7 use Drupal\Core\Plugin\DefaultPluginManager; | |
8 | |
9 /** | |
10 * Manager for Views Slideshow Widget plugins. | |
11 */ | |
12 class ViewsSlideshowWidgetPluginManager extends DefaultPluginManager { | |
13 | |
14 /** | |
15 * Constructs a new ViewsSlideshowWidgetPluginManager. | |
16 * | |
17 * @param \Traversable $namespaces | |
18 * An object that implements \Traversable which contains the root paths | |
19 * keyed by the corresponding namespace to look for plugin implementations. | |
20 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend | |
21 * Cache backend instance to use. | |
22 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | |
23 * The module handler. | |
24 */ | |
25 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { | |
26 parent::__construct('Plugin/ViewsSlideshowWidget', $namespaces, $module_handler, 'Drupal\views_slideshow\ViewsSlideshowWidgetInterface', 'Drupal\views_slideshow\Annotation\ViewsSlideshowWidget'); | |
27 $this->alterInfo('views_slideshow_widget_info'); | |
28 $this->setCacheBackend($cache_backend, 'views_slideshow_widget'); | |
29 } | |
30 | |
31 /** | |
32 * Gets the definition of all or filtered plugins for this type. | |
33 * | |
34 * @param mixed $type | |
35 * A string or an array of types to filter on. | |
36 * | |
37 * @return mixed | |
38 * An array of plugin definitions. Keys are plugin IDs. | |
39 */ | |
40 public function getDefinitions($type = NULL) { | |
41 $definitions = parent::getDefinitions(); | |
42 | |
43 // Filter widgets to keep only required types. | |
44 if (!empty($type)) { | |
45 foreach ($definitions as $widgetId => $widgetInfo) { | |
46 if ((is_array($type) && !in_array($widgetInfo['type'], $type)) || (is_string($type) && $widgetInfo['type'] !== $type)) { | |
47 unset($definitions[$widgetId]); | |
48 } | |
49 } | |
50 } | |
51 | |
52 return $definitions; | |
53 } | |
54 | |
55 } |