From 13cfcebc56372307c890234a8f386c32cb0f5475 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 16 Apr 2018 12:15:09 -0400 Subject: [PATCH] Prevent empty labels on result checkboxes. (#1126) --- languages/en.ini | 1 + module/VuFind/src/VuFind/View/Helper/Root/Record.php | 6 +++--- .../src/VuFindTest/View/Helper/Root/RecordTest.php | 8 ++++---- themes/bootstrap3/templates/record/checkbox.phtml | 1 + themes/bootstrap3/templates/search/list-list.phtml | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/languages/en.ini b/languages/en.ini index 581440b1392..c9758db4aaa 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -844,6 +844,7 @@ Requests = "Requests" Reserves = "Reserves" Reserves Search = "Reserves Search" Reserves Search Results = "Reserves Search Results" +result_checkbox_label = "Select result number %%number%%" result_count = "%%count%% results" Results = "Results" results = "results" diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index fa7448e53a6..cea7cb35a3a 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -413,16 +413,16 @@ class Record extends AbstractHelper * * @param string $idPrefix Prefix for checkbox HTML ids * @param string $formAttr ID of form for [form] attribute + * @param int $number Result number (for label of checkbox) * * @return string */ - public function getCheckbox($idPrefix = '', $formAttr = false) + public function getCheckbox($idPrefix = '', $formAttr = false, $number = null) { - static $checkboxCount = 0; $id = $this->driver->getSourceIdentifier() . '|' . $this->driver->getUniqueId(); $context - = ['id' => $id, 'count' => $checkboxCount++, 'prefix' => $idPrefix]; + = ['id' => $id, 'number' => $number, 'prefix' => $idPrefix]; if ($formAttr) { $context['formAttr'] = $formAttr; } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php index 6151a184dc0..b3f0715824a 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php @@ -273,17 +273,17 @@ class RecordTest extends \PHPUnit\Framework\TestCase { $context = $this->getMockContext(); $context->expects($this->at(1))->method('renderInContext') - ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'count' => 0, 'prefix' => 'bar', 'formAttr' => 'foo'])) + ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'number' => 1, 'prefix' => 'bar', 'formAttr' => 'foo'])) ->will($this->returnValue('success')); $context->expects($this->at(2))->method('renderInContext') - ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'count' => 1, 'prefix' => 'bar', 'formAttr' => 'foo'])) + ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'number' => 2, 'prefix' => 'bar', 'formAttr' => 'foo'])) ->will($this->returnValue('success')); $record = $this->getRecord( $this->loadRecordFixture('testbug1.json'), [], $context ); // We run the test twice to ensure that checkbox incrementing works properly: - $this->assertEquals('success', $record->getCheckbox('bar', 'foo')); - $this->assertEquals('success', $record->getCheckbox('bar', 'foo')); + $this->assertEquals('success', $record->getCheckbox('bar', 'foo', 1)); + $this->assertEquals('success', $record->getCheckbox('bar', 'foo', 2)); } /** diff --git a/themes/bootstrap3/templates/record/checkbox.phtml b/themes/bootstrap3/templates/record/checkbox.phtml index 53d3b326dcb..7c37bb0ab24 100644 --- a/themes/bootstrap3/templates/record/checkbox.phtml +++ b/themes/bootstrap3/templates/record/checkbox.phtml @@ -1,5 +1,6 @@ <label class="record-checkbox hidden-print"> <input class="checkbox-select-item" type="checkbox" name="ids[]" value="<?=$this->escapeHtmlAttr($this->id) ?>"<?php if(isset($this->formAttr)): ?> form="<?=$this->formAttr ?>"<?php endif; ?>/> <span class="checkbox-icon"></span> + <?php if (strlen($this->number ?? '') > 0): ?><span class="sr-only"><?=$this->transEsc('result_checkbox_label', ['%%number%%' => $this->number]) ?></span><?php endif; ?> </label> <input type="hidden" name="idsAll[]" value="<?=$this->escapeHtmlAttr($this->id) ?>"<?php if(isset($this->formAttr)): ?> form="<?=$this->formAttr ?>"<?php endif; ?>/> diff --git a/themes/bootstrap3/templates/search/list-list.phtml b/themes/bootstrap3/templates/search/list-list.phtml index d8783c90565..af656e815b8 100644 --- a/themes/bootstrap3/templates/search/list-list.phtml +++ b/themes/bootstrap3/templates/search/list-list.phtml @@ -4,7 +4,7 @@ <?php $recordNumber = $this->results->getStartRecord() + $i - $this->indexStart; ?> <div id="result<?=$i++ ?>" class="result<?=$current->supportsAjaxStatus()?' ajaxItem':''?>"> <?php if (isset($this->showCheckboxes) && $this->showCheckboxes): ?> - <?=$this->record($current)->getCheckbox('', 'search-cart-form')?> + <?=$this->record($current)->getCheckbox('', 'search-cart-form', $recordNumber)?> <?php endif; ?> <div class="record-number"> <?=$recordNumber ?> -- GitLab