diff --git a/diff.install b/diff.install index 22a55b7..072a5dc 100644 --- a/diff.install +++ b/diff.install @@ -35,3 +35,16 @@ function diff_update_8003() { $config->clear('general_settings.theme'); $config->save(); } + +/** + * Enable all layout plugins to be used. + */ +function diff_update_8004() { + $config = \Drupal::configFactory()->getEditable('diff.settings'); + $plugins = \Drupal::service('plugin.manager.diff.layout')->getDefinitions(); + foreach ($plugins as $key => $value) { + $plugin_options[$key] = $value['label']; + $config->set('general_settings.layout_plugins.' . $key . '.enabled', TRUE); + } + $config->save(); +} \ No newline at end of file diff --git a/src/DiffLayoutManager.php b/src/DiffLayoutManager.php index a31b931..5c1e4f5 100644 --- a/src/DiffLayoutManager.php +++ b/src/DiffLayoutManager.php @@ -58,20 +58,18 @@ class DiffLayoutManager extends DefaultPluginManager { } /** - * Gets the applicable plugin options for a given field. + * Gets the applicable layout plugins. * - * Loop over the plugins that can be applied to the field and builds an array - * of possible plugins based on each plugin weight. + * Loop over the plugins that can be used to display the diff comparison + * sorting them by the weight. * * @return array - * The plugin option for the given field based on plugin weight. + * The layout plugin options. */ public function getPluginOptions() { $plugins = $this->config->get('general_settings' . '.' . 'layout_plugins'); $plugin_options = []; - $plugins_order = []; - // If layout settings have been saved used them, otherwise load all the - // plugins available. + // 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'); @@ -80,17 +78,6 @@ class DiffLayoutManager extends DefaultPluginManager { if ($value['enabled']) { $plugin_options[$key] = $plugin['label']; } - $plugins_order[$key] = $plugin['label']; - } - // If any plugin is selected, all selected. - if ($plugin_options == []) { - $plugin_options = $plugins_order; - } - } - else { - $plugins = $this->getDefinitions(); - foreach ($plugins as $key => $value) { - $plugin_options[$key] = $value['label']; } } return $plugin_options; diff --git a/src/Form/GeneralSettingsForm.php b/src/Form/GeneralSettingsForm.php index db67dfe..bb01e3c 100644 --- a/src/Form/GeneralSettingsForm.php +++ b/src/Form/GeneralSettingsForm.php @@ -64,7 +64,7 @@ class GeneralSettingsForm extends ConfigFormBase { foreach ($layout_plugins as $id => $layout_plugin) { $layout_plugins_order[$id] = [ 'label' => $layout_plugin['label'], - 'enabled' => $config->get('general_settings' . '.' . 'layout_plugins')[$id]['enabled'] ?: FALSE, + 'enabled' => $config->get('general_settings' . '.' . 'layout_plugins')[$id]['enabled'], 'weight' => $config->get('general_settings' . '.' . 'layout_plugins')[$id]['weight'] ?: $weight, ]; $weight++; @@ -74,7 +74,7 @@ class GeneralSettingsForm extends ConfigFormBase { '#type' => 'table', '#header' => [t('Layout'), t('Weight')], '#empty' => t('There are no items yet. Add an item.'), - '#suffix' => '
' . $this->t('The layout plugins that are enabled for displaying the diff comparison. Select none to allow all plugins.') .'
', + '#suffix' => '
' . $this->t('The layout plugins that are enabled for displaying the diff comparison.') .'
', '#tabledrag' => [ [ 'action' => 'order',