Unverified Commit bcfce36c authored by alexpott's avatar alexpott
Browse files

Issue #2847921 by JayKandari, arshadcn, Chi, Krzysztof Domański, cilefen, xjm:...

Issue #2847921 by JayKandari, arshadcn, Chi, Krzysztof Domański, cilefen, xjm: Use "number" form element in Views pager settings form
parent 6d3fbe9a
......@@ -43,6 +43,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['quantity'] = [
'#type' => 'number',
'#min' => 0,
'#title' => $this->t('Number of pager links visible'),
'#description' => $this->t('Specify the number of links to pages to display in the pager.'),
'#default_value' => $this->options['quantity'],
......
......@@ -50,7 +50,8 @@ protected function defineOptions() {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['offset'] = [
'#type' => 'textfield',
'#type' => 'number',
'#min' => 0,
'#title' => $this->t('Offset (number of items to skip)'),
'#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
'#default_value' => $this->options['offset'],
......
......@@ -41,13 +41,15 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$pager_text = $this->displayHandler->getPagerText();
$form['items_per_page'] = [
'#title' => $pager_text['items per page title'],
'#type' => 'textfield',
'#type' => 'number',
'#min' => 0,
'#description' => $pager_text['items per page description'],
'#default_value' => $this->options['items_per_page'],
];
$form['offset'] = [
'#type' => 'textfield',
'#type' => 'number',
'#min' => 0,
'#title' => $this->t('Offset (number of items to skip)'),
'#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
'#default_value' => $this->options['offset'],
......
......@@ -47,12 +47,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['items_per_page'] = [
'#title' => $pager_text['items per page title'],
'#type' => 'number',
'#min' => 0,
'#description' => $pager_text['items per page description'],
'#default_value' => $this->options['items_per_page'],
];
$form['offset'] = [
'#type' => 'number',
'#min' => 0,
'#title' => $this->t('Offset (number of items to skip)'),
'#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
'#default_value' => $this->options['offset'],
......@@ -60,6 +62,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['id'] = [
'#type' => 'number',
'#min' => 0,
'#title' => $this->t('Pager ID'),
'#description' => $this->t("Unless you're experiencing problems with pagers related to this view, 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."),
'#default_value' => $this->options['id'],
......@@ -67,6 +70,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['total_pages'] = [
'#type' => 'number',
'#min' => 0,
'#title' => $this->t('Number of pages'),
'#description' => $this->t('Leave empty to show all pages.'),
'#default_value' => $this->options['total_pages'],
......
......@@ -53,10 +53,32 @@ public function testStorePagerSettings() {
$this->drupalGet('admin/structure/views/view/test_view/edit');
$edit = [
'pager[type]' => 'some',
];
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/pager', $edit, t('Apply'));
$this->assertFieldByXPath('//input[@name="pager_options[items_per_page]" and @type="number" and @min="0"]', 10, '"Items per page" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
$edit = [
'pager[type]' => 'none',
];
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/pager', $edit, t('Apply'));
$this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
$edit = [
'pager[type]' => 'full',
];
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/pager', $edit, t('Apply'));
$this->assertFieldByXPath('//input[@name="pager_options[items_per_page]" and @type="number" and @min="0"]', 10, '"Items to display" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[id]" and @type="number" and @min="0"]', 0, '"Pager ID" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[total_pages]" and @type="number" and @min="0"]', '', '"Number of pages" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[quantity]" and @type="number" and @min="0"]', 9, '"Number of pager links" field was found.');
$edit = [
'pager_options[items_per_page]' => 20,
];
......@@ -121,6 +143,11 @@ public function testStorePagerSettings() {
$this->assertFieldByName('override[dropdown]', 'page_1', 'The override element is displayed on plugin selection form.');
$this->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager_options');
$this->assertNoFieldByName('override[dropdown]', NULL, 'The override element is not displayed on plugin settings form.');
$this->assertFieldByXPath('//input[@name="pager_options[items_per_page]" and @type="number" and @min="0"]', 20, '"Items per page" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[id]" and @type="number" and @min="0"]', 0, '"Pager ID" field was found.');
$this->assertFieldByXPath('//input[@name="pager_options[total_pages]" and @type="number" and @min="0"]', '', '"Number of pages" field was found.');
}
/**
......
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