Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / diff / src / DiffLayoutManager.php
1 <?php
2
3 namespace Drupal\diff;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Config\ConfigFactoryInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\Extension\ModuleHandlerInterface;
9 use Drupal\Core\Plugin\DefaultPluginManager;
10
11 /**
12  * Plugin type manager for field diff builders.
13  *
14  * @ingroup diff_layout_builder
15  */
16 class DiffLayoutManager extends DefaultPluginManager {
17
18   /**
19    * The entity type manager.
20    *
21    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
22    */
23   protected $entityTypeManager;
24
25   /**
26    * Wrapper object for simple configuration from diff.settings.yml.
27    *
28    * @var \Drupal\Core\Config\ImmutableConfig
29    */
30   protected $config;
31
32   /**
33    * Wrapper object for simple configuration from diff.plugins.yml.
34    *
35    * @var \Drupal\Core\Config\ImmutableConfig
36    */
37   protected $layoutPluginsConfig;
38
39   /**
40    * Constructs a DiffLayoutManager object.
41    *
42    * @param \Traversable $namespaces
43    *   An object that implements \Traversable which contains the root paths
44    *   keyed by the corresponding namespace to look for plugin implementations.
45    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
46    *   Cache backend instance to use.
47    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
48    *   The module handler.
49    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
50    *   The entity type manager.
51    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
52    *   The configuration factory.
53    */
54   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
55     parent::__construct('Plugin/diff/Layout', $namespaces, $module_handler, '\Drupal\diff\DiffLayoutInterface', 'Drupal\diff\Annotation\DiffLayoutBuilder');
56
57     $this->setCacheBackend($cache_backend, 'diff_layout_builder_plugins');
58     $this->alterInfo('diff_layout_builder_info');
59     $this->entityTypeManager = $entity_type_manager;
60     $this->config = $config_factory->get('diff.settings');
61     $this->layoutPluginsConfig = $config_factory->get('diff.layout_plugins');
62   }
63
64   /**
65    * Gets the applicable layout plugins.
66    *
67    * Loop over the plugins that can be used to display the diff comparison
68    * sorting them by the weight.
69    *
70    * @return array
71    *   The layout plugin options.
72    */
73   public function getPluginOptions() {
74     $plugins = $this->config->get('general_settings.layout_plugins');
75     $plugin_options = [];
76     // Get the plugins sorted and build an array keyed by the plugin id.
77     if ($plugins) {
78       // Sort the plugins based on their weight.
79       uasort($plugins, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
80       foreach ($plugins as $key => $value) {
81         if ($this->hasDefinition($key)) {
82           $plugin = $this->getDefinition($key);
83           if ($plugin && $value['enabled']) {
84             $plugin_options[$key] = $plugin['label'];
85           }
86         }
87       }
88     }
89     return $plugin_options;
90   }
91
92   /**
93    * Gets the default layout plugin selected.
94    *
95    * Take the first option of the array returned by getPluginOptions.
96    *
97    * @return string
98    *   The id of the default plugin.
99    */
100   public function getDefaultLayout() {
101     $plugins = array_keys($this->getPluginOptions());
102     return reset($plugins);
103   }
104
105   /**
106    * {@inheritdoc}
107    */
108   public function findDefinitions() {
109     $definitions = parent::findDefinitions();
110
111     // Remove plugin html_diff if library is not present.
112     $has_htmlDiffAdvanced = class_exists('\HtmlDiffAdvanced');
113     if (!$has_htmlDiffAdvanced) {
114       unset($definitions['visual_inline']);
115     }
116     return $definitions;
117   }
118
119 }