Pull merge.
[yaffs-website] / web / modules / contrib / search_api_synonym / src / Import / ImportPluginManager.php
1 <?php
2
3 namespace Drupal\search_api_synonym\Import;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
8
9 /**
10  * Base class for search api synonym import plugin managers.
11  *
12  * @ingroup plugin_api
13  */
14 class ImportPluginManager extends DefaultPluginManager {
15
16   /**
17    * Active plugin id
18    *
19    * @var string
20    */
21   protected $pluginId;
22
23   /**
24    * Import options.
25    *
26    * @var array
27    */
28   protected $importOptions;
29
30   /**
31    * {@inheritdoc}
32    */
33   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
34     parent::__construct('Plugin/search_api_synonym/import', $namespaces, $module_handler, 'Drupal\search_api_synonym\Import\ImportPluginInterface', 'Drupal\search_api_synonym\Annotation\SearchApiSynonymImport');
35     $this->alterInfo('search_api_synonym_import_info');
36     $this->setCacheBackend($cache_backend, 'search_api_synonym_import_info_plugins');
37   }
38
39   /**
40    * Set active plugin
41    *
42    * @param string $plugin_id
43    *   The active plugin.
44    */
45   public function setPluginId($plugin_id) {
46     $this->pluginId = $plugin_id;
47   }
48
49   /**
50    * Get active plugin
51    *
52    * @return string
53    *   The active plugin.
54    */
55   public function getPluginId() {
56     return $this->pluginId;
57   }
58
59   /**
60    * Gets a list of available import plugins.
61    *
62    * @return array
63    *   An array with the plugin names as keys and the descriptions as values.
64    */
65   public function getAvailableImportPlugins() {
66     // Use plugin system to get list of available import plugins.
67     $plugins = $this->getDefinitions();
68
69     $output = [];
70     foreach ($plugins as $id => $definition) {
71       $output[$id] = $definition;
72     }
73
74     return $output;
75   }
76
77   /**
78    * Validate that a specific import plugin exists.
79    *
80    * @param string $plugin
81    *   The plugin machine name.
82    *
83    * @return boolean
84    *   TRUE if the plugin exists.
85    */
86   public function validatePlugin($plugin) {
87     if ($this->getDefinition($plugin, FALSE)) {
88       return TRUE;
89     }
90     else {
91       return FALSE;
92     }
93   }
94
95 }