Commit d1a751e1 authored by webchick's avatar webchick

Issue #2210177 by andypost: [Followup] Use getSetting() in comment formatter.

parent e9782006
......@@ -142,8 +142,8 @@ public function viewElements(FieldItemListInterface $items) {
comment_prepare_thread($comments);
$build = $this->viewBuilder->viewMultiple($comments);
$build['pager']['#theme'] = 'pager';
if (!empty($this->settings['pager_id'])) {
$build['pager']['#element'] = $this->settings['pager_id'];
if ($this->getSetting('pager_id')) {
$build['pager']['#element'] = $this->getSetting('pager_id');
}
$output['comments'] = $build;
}
......@@ -213,7 +213,7 @@ public function settingsForm(array $form, array &$form_state) {
'#type' => 'select',
'#title' => $this->t('Pager ID'),
'#options' => range(0, 10),
'#default_value' => empty($this->settings['pager_id']) ? 0 : $this->settings['pager_id'],
'#default_value' => $this->getSetting('pager_id'),
'#description' => $this->t("Unless you're experiencing problems with pagers related to this field, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."),
);
return $element;
......@@ -224,9 +224,9 @@ public function settingsForm(array $form, array &$form_state) {
*/
public function settingsSummary() {
// Only show a summary if we're using a non-standard pager id.
if (!empty($this->settings['pager_id'])) {
if ($this->getSetting('pager_id')) {
return array($this->t('Pager ID: @id', array(
'@id' => $this->settings['pager_id'],
'@id' => $this->getSetting('pager_id'),
)));
}
return array();
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\comment\Tests\CommentPagerTest.
* Contains \Drupal\comment\Tests\CommentPagerTest.
*/
namespace Drupal\comment\Tests;
......@@ -273,7 +273,6 @@ function testCommentNewPageIndicator() {
* Confirms comment paging works correctly with two pagers.
*/
function testTwoPagers() {
$this->drupalLogin($this->admin_user);
// Add another field to article content-type.
$this->container->get('comment.manager')->addDefaultField('node', 'article', 'comment_2');
// Set default to display comment list with unique pager id.
......@@ -287,6 +286,24 @@ function testTwoPagers() {
)
))
->save();
// Make sure pager appears in formatter summary and settings form.
$account = $this->drupalCreateUser(array('administer node display'));
$this->drupalLogin($account);
$this->drupalGet('admin/structure/types/manage/article/display');
$this->assertNoText(t('Pager ID: @id', array('@id' => 0)), 'No summary for standard pager');
$this->assertText(t('Pager ID: @id', array('@id' => 1)));
$this->drupalPostAjaxForm(NULL, array(), 'comment_settings_edit');
// Change default pager to 2.
$this->drupalPostForm(NULL, array('fields[comment][settings_edit_form][settings][pager_id]' => 2), t('Save'));
$this->assertText(t('Pager ID: @id', array('@id' => 2)));
// Revert the changes back.
$this->drupalPostAjaxForm(NULL, array(), 'comment_settings_edit');
$this->drupalPostForm(NULL, array('fields[comment][settings_edit_form][settings][pager_id]' => 0), t('Save'));
$this->assertNoText(t('Pager ID: @id', array('@id' => 0)), 'No summary for standard pager');
$this->drupalLogin($this->admin_user);
// Add a new node with both comment fields open.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->id()));
// Set comment options.
......@@ -333,4 +350,5 @@ function testTwoPagers() {
$this->assertRaw('Comment 2 on field comment');
$this->assertRaw('Comment 2 on field comment_2');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment