diff --git a/src/Controller/PluginRevisionController.php b/src/Controller/PluginRevisionController.php index 9661938..6661780 100644 --- a/src/Controller/PluginRevisionController.php +++ b/src/Controller/PluginRevisionController.php @@ -159,7 +159,6 @@ class PluginRevisionController extends ControllerBase { */ protected function buildLayoutNavigation(EntityInterface $entity, $left_revision_id, $right_revision_id, $active_filter) { $links = []; - debug($this->diffLayoutManager->getDefaultLayout()); $layouts = $this->diffLayoutManager->getPluginOptions(); foreach ($layouts as $key => $value) { $links[$key] = array( diff --git a/src/DiffLayoutManager.php b/src/DiffLayoutManager.php index 0e8f86d..a31b931 100644 --- a/src/DiffLayoutManager.php +++ b/src/DiffLayoutManager.php @@ -69,14 +69,22 @@ class DiffLayoutManager extends DefaultPluginManager { 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. if ($plugins) { // Sort the plugins based on their weight. uasort($plugins, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); foreach ($plugins as $key => $value) { + $plugin = $this->getDefinition($key); if ($value['enabled']) { - $plugin = $this->getDefinition($key); $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 { @@ -85,13 +93,19 @@ class DiffLayoutManager extends DefaultPluginManager { $plugin_options[$key] = $value['label']; } } - debug($plugin_options); 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 = $this->getPluginOptions(); - debug($plugins[0]); return array_keys($plugins[0]); } } diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php index 717e749..144195e 100755 --- a/src/Routing/RouteSubscriber.php +++ b/src/Routing/RouteSubscriber.php @@ -24,10 +24,6 @@ class RouteSubscriber extends RouteSubscriberBase { ) ); } - - $default = \Drupal::service('plugin.manager.diff.layout')->getDefaultLayout(); - $route = $collection->get('diff.revisions_diff'); - $route->addDefaults(['filter' => $default]); } } diff --git a/src/Tests/AdminFormsTest.php b/src/Tests/AdminFormsTest.php index 0e3e034..8c05d52 100644 --- a/src/Tests/AdminFormsTest.php +++ b/src/Tests/AdminFormsTest.php @@ -78,14 +78,28 @@ class AdminFormsTest extends DiffTestBase { 'layout_plugins[markdown][weight]' => '10', ]; $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration')); - $this->createNode(['title' => 'great_title']); - $node = $this->getNodeByTitle('great_title'); - $node->title = 'greater_title'; - $node->setNewRevision(TRUE); - $node->save(); + // Create a node with a revision. + $edit = [ + 'title[0][value]' => 'great_title', + 'body[0][value]' => '
great_body
', + ]; + $this->drupalPostForm('node/add/article', $edit, t('Save and publish')); + $this->clickLink('Edit'); + $edit = [ + 'title[0][value]' => 'greater_title', + 'body[0][value]' => 'greater_body
', + ]; + $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + + // Check all the links are displayed. + $node = $this->getNodeByTitle('greater_title'); $this->drupalGet('node/' . $node->id() . '/revisions'); $this->drupalPostForm(NULL, [], t('Compare')); + $this->assertLink('Single Column'); + $this->assertLink('Markdown'); + $this->assertLink('Standard'); + // Change the settings of the layouts, disable the single column. $edit = [ 'layout_plugins[classic][weight]' => '11', 'layout_plugins[classic][enabled]' => TRUE, @@ -93,10 +107,17 @@ class AdminFormsTest extends DiffTestBase { ]; $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration')); + // Check the revision display. $this->drupalGet('node/' . $node->id() . '/revisions'); $this->drupalPostForm(NULL, [], t('Compare')); - $this->assertNoLink('Single column'); + $this->assertResponse(200); + $this->assertNoLink('Single Column'); + $this->assertLink('Markdown'); + $this->assertLink('Standard'); + $this->assertText('great_title'); + // @todo verify order of the plugins and disable classic layout. Set the + // default layout during routing. } }