annotate modules/contrib/views_slideshow/src/ViewsSlideshowWidgetPluginManager.php @ 19:fa3358dc1485 tip

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