setCacheBackend($cache_backend, 'diff_layout_builder_plugins'); $this->alterInfo('diff_layout_builder_info'); $this->entityTypeManager = $entity_type_manager; $this->config = $config_factory->get('diff.settings'); $this->layoutPluginsConfig = $config_factory->get('diff.layout_plugins'); } /** * Gets the applicable layout plugins. * * Loop over the plugins that can be used to display the diff comparison * sorting them by the weight. * * @return array * The layout plugin options. */ public function getPluginOptions() { $plugins = $this->config->get('general_settings.layout_plugins'); $plugin_options = []; // Get the plugins sorted and build an array keyed by the plugin id. if ($plugins) { // Sort the plugins based on their weight. uasort($plugins, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); foreach ($plugins as $key => $value) { if ($this->hasDefinition($key)) { $plugin = $this->getDefinition($key); if ($plugin && $value['enabled']) { $plugin_options[$key] = $plugin['label']; } } } } return $plugin_options; } /** * Gets the default layout plugin selected. * * Take the first option of the array returned by getPluginOptions. * * @return string * The id of the default plugin. */ public function getDefaultLayout() { $plugins = array_keys($this->getPluginOptions()); return reset($plugins); } /** * {@inheritdoc} */ public function findDefinitions() { $definitions = parent::findDefinitions(); // Remove plugin html_diff if library is not present. $has_htmlDiffAdvanced = class_exists('\HtmlDiffAdvanced'); if (!$has_htmlDiffAdvanced) { unset($definitions['visual_inline']); } return $definitions; } }