diff -u b/src/DiffLayoutManager.php b/src/DiffLayoutManager.php --- b/src/DiffLayoutManager.php +++ b/src/DiffLayoutManager.php @@ -94,5 +94,6 @@ public function getDefaultLayout() { $plugins = $this->getPluginOptions(); - return array_keys($plugins[0]); + list($plugin) = array_keys($plugins); + return $plugin; } } diff -u b/src/Form/GeneralSettingsForm.php b/src/Form/GeneralSettingsForm.php --- b/src/Form/GeneralSettingsForm.php +++ b/src/Form/GeneralSettingsForm.php @@ -4,10 +4,38 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\diff\DiffLayoutManager; +use Symfony\Component\DependencyInjection\ContainerInterface; class GeneralSettingsForm extends ConfigFormBase { /** + * The field diff layout plugin manager service. + * + * @var \Drupal\diff\DiffLayoutManager + */ + protected $diffLayoutManager; + + /** + * GeneralSettingsForm constructor. + * + * @param \Drupal\diff\DiffLayoutManager $diff_layout_manager + * The diff layout manager service. + */ + public function __construct(DiffLayoutManager $diff_layout_manager) { + $this->diffLayoutManager = $diff_layout_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.diff.layout') + ); + } + + /** * {@inheritdoc} */ public function getFormId() { @@ -58,7 +86,7 @@ '#options' => $options, ); - $layout_plugins = \Drupal::service('plugin.manager.diff.layout')->getDefinitions(); + $layout_plugins = $this->diffLayoutManager->getDefinitions(); $weight = count($layout_plugins) + 1; $layout_plugins_order = []; foreach ($layout_plugins as $id => $layout_plugin) { diff -u b/src/Tests/AdminFormsTest.php b/src/Tests/AdminFormsTest.php --- b/src/Tests/AdminFormsTest.php +++ b/src/Tests/AdminFormsTest.php @@ -91,33 +91,50 @@ ]; $this->drupalPostForm(NULL, $edit, t('Save and keep published')); - // Check all the links are displayed. + // Assert the diff display uses the classic layout. $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'); + $text = $this->xpath('//tbody/tr[4]/td[2]'); + $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), '
great_body
'); // Change the settings of the layouts, disable the single column. $edit = [ 'layout_plugins[classic][weight]' => '11', - 'layout_plugins[classic][enabled]' => TRUE, - 'layout_plugins[markdown][enabled]' => TRUE, + 'layout_plugins[single_column][enabled]' => FALSE, ]; $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration')); - // Check the revision display. + // Assert the diff display uses the markdown layout. $this->drupalGet('node/' . $node->id() . '/revisions'); $this->drupalPostForm(NULL, [], t('Compare')); $this->assertResponse(200); $this->assertNoLink('Single Column'); $this->assertLink('Markdown'); $this->assertLink('Standard'); - $this->assertText('great_title'); + $text = $this->xpath('//tbody/tr[4]/td[2]'); + $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), 'great_body'); - // @todo verify order of the plugins and disable classic layout. Set the - // default layout during routing. + // Change the settings of the layouts, enable single column. + $edit = [ + 'layout_plugins[single_column][enabled]' => TRUE, + 'layout_plugins[classic][enabled]' => FALSE, + 'layout_plugins[markdown][enabled]' => FALSE, + ]; + $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration')); + + // Assert the diff display uses the single column layout. + $this->drupalGet('node/' . $node->id() . '/revisions'); + $this->drupalPostForm(NULL, [], t('Compare')); + $this->assertResponse(200); + $this->assertLink('Single Column'); + $this->assertNoLink('Markdown'); + $this->assertNoLink('Standard'); + $text = $this->xpath('//tbody/tr[5]/td[2]'); + $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), 'great_body
'); } } only in patch2: unchanged: --- a/config/install/diff.settings.yml +++ b/config/install/diff.settings.yml @@ -3,3 +3,13 @@ general_settings: context_lines_leading: 1 context_lines_trailing: 1 revision_pager_limit: 50 + layout_plugins: + classic: + enabled: true + weight: -50 + markdown: + enabled: true + weight: -49 + single_column: + enabled: true + weight: -48 only in patch2: unchanged: --- a/diff.routing.yml +++ b/diff.routing.yml @@ -3,7 +3,6 @@ diff.revisions_diff: defaults: _controller: '\Drupal\diff\Controller\NodeRevisionController::compareNodeRevisions' _title: Diff General Settings - filter: 'classic' requirements: _access_node_revision: 'view' options: only in patch2: unchanged: --- a/src/Form/RevisionOverviewForm.php +++ b/src/Form/RevisionOverviewForm.php @@ -3,6 +3,7 @@ namespace Drupal\diff\Form; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\diff\DiffLayoutManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormBase; @@ -58,6 +59,12 @@ class RevisionOverviewForm extends FormBase { */ protected $config; + /** + * The field diff layout plugin manager service. + * + * @var \Drupal\diff\DiffLayoutManager + */ + protected $diffLayoutManager; /** * Constructs a RevisionOverviewForm object. @@ -72,14 +79,17 @@ class RevisionOverviewForm extends FormBase { * The renderer service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param DiffLayoutManager $diff_layout_manager + * DiffLayoutManager service. */ - public function __construct(EntityManagerInterface $entityManager, AccountInterface $currentUser, DateFormatter $date, RendererInterface $renderer, LanguageManagerInterface $language_manager) { + public function __construct(EntityManagerInterface $entityManager, AccountInterface $currentUser, DateFormatter $date, RendererInterface $renderer, LanguageManagerInterface $language_manager, DiffLayoutManager $diff_layout_manager) { $this->entityManager = $entityManager; $this->currentUser = $currentUser; $this->date = $date; $this->renderer = $renderer; $this->languageManager = $language_manager; $this->config = $this->config('diff.settings'); + $this->diffLayoutManager = $diff_layout_manager; } /** @@ -91,7 +101,8 @@ class RevisionOverviewForm extends FormBase { $container->get('current_user'), $container->get('date.formatter'), $container->get('renderer'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('plugin.manager.diff.layout') ); } @@ -348,6 +359,7 @@ class RevisionOverviewForm extends FormBase { 'node' => $nid, 'left_revision' => $vid_left, 'right_revision' => $vid_right, + 'filter' => $this->diffLayoutManager->getDefaultLayout(), ) ); $form_state->setRedirectUrl($redirect_url);