Fix ReadItLater checkbox label on bulk add (#1916)

* Fix ReadItLater checkbox label on bulk add

Adds a random string to the HTML ID so it can be unique in batch more,
where there are multiple checkboxes.

* Fix PHPUnit compatibility polyfill
This commit is contained in:
ArthurHoaro 2022-11-26 16:39:35 +01:00 committed by GitHub
parent f28b9d550e
commit c971344ddb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View file

@ -65,8 +65,11 @@ function hook_readitlater_render_editlink(array $data, ConfigManager $conf): arr
// Load HTML into a string // Load HTML into a string
$html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readitlater/readitlater_editlink.html'); $html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readitlater/readitlater_editlink.html');
// Random ID for batch shaare (multiple inputs on the same page)
$random = uniqid();
// Replace value in HTML if it exists in $data // Replace value in HTML if it exists in $data
$html = sprintf($html, $default ? 'checked' : ''); $html = sprintf($html, $random, $default ? 'checked' : '', $random);
// field_plugin // field_plugin
$data['edit_link_plugin'][] = $html; $data['edit_link_plugin'][] = $html;

View file

@ -1 +1 @@
<input type="checkbox" name="readitlater" id="readitlater" %s /><label for="readitlater"> Read it later</label><br> <input type="checkbox" name="readitlater" id="readitlater_%s" %s /><label for="readitlater_%s"> Read it later</label><br>

View file

@ -278,8 +278,8 @@ public function testReadItLaterRenderEditLinkDefaultOff(): void
]; ];
$data = hook_readitlater_render_editlink($originalData, $this->confDefaultTheme); $data = hook_readitlater_render_editlink($originalData, $this->confDefaultTheme);
static::assertContainsPolyfill( static::assertRegExp(
'<input type="checkbox" name="readitlater" id="readitlater" />', '#<input type="checkbox" name="readitlater" id="readitlater_[a-z0-9]+" />#',
$data['edit_link_plugin'][0] $data['edit_link_plugin'][0]
); );
@ -288,8 +288,8 @@ public function testReadItLaterRenderEditLinkDefaultOff(): void
$data = hook_readitlater_render_editlink($originalData, $this->confDefaultTheme); $data = hook_readitlater_render_editlink($originalData, $this->confDefaultTheme);
static::assertContainsPolyfill( static::assertRegExp(
'<input type="checkbox" name="readitlater" id="readitlater" />', '#<input type="checkbox" name="readitlater" id="readitlater_[a-z0-9]+" />#',
$data['edit_link_plugin'][0] $data['edit_link_plugin'][0]
); );
} }
@ -307,8 +307,8 @@ public function testReadItLaterRenderEditLinkDefaultOn(): void
]; ];
$data = hook_readitlater_render_editlink($originalData, $this->confDefaultTheme); $data = hook_readitlater_render_editlink($originalData, $this->confDefaultTheme);
static::assertContainsPolyfill( static::assertRegExp(
'<input type="checkbox" name="readitlater" id="readitlater" checked />', '#<input type="checkbox" name="readitlater" id="readitlater_[a-z0-9]+" checked />#',
$data['edit_link_plugin'][0] $data['edit_link_plugin'][0]
); );
} }