Skip to content

Commit 66df79f

Browse files
committed
MAGE-986 Link checkbox labels
1 parent 5fbac83 commit 66df79f

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

Block/Adminhtml/System/Config/Form/Field/Checkboxes.php

+30-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,32 @@ class Checkboxes extends Field
1010
protected function _getElementHtml(AbstractElement $element)
1111
{
1212
$elementId = $element->getHtmlId();
13-
$html = <<<CSS
13+
14+
$html = $this->getCss($elementId);
15+
16+
$html .= sprintf('<div id="%s">', $elementId);
17+
$name = $element->getName();
18+
$options = $element->getValues();
19+
$values = empty($element->getValue()) ? [] : explode(',', $element->getValue()); // store as CSV in config
20+
21+
foreach ($options as $key => $option) {
22+
$value = $option['value'];
23+
$html .= $this->getCheckboxHtml(
24+
$elementId . '_' . $key,
25+
$name,
26+
$value,
27+
in_array($value, $values),
28+
$option['label'],
29+
array_key_exists('description', $option) ? $option['description'] : ''
30+
);
31+
}
32+
33+
$html .= '</div>';
34+
return $html;
35+
}
36+
37+
protected function getCss($elementId): string {
38+
return <<<CSS
1439
<style>
1540
#$elementId .form-group {
1641
display: grid;
@@ -37,28 +62,10 @@ protected function _getElementHtml(AbstractElement $element)
3762
}
3863
</style>
3964
CSS;
40-
41-
$html .= sprintf('<div id="%s">', $elementId);
42-
$name = $element->getName();
43-
$options = $element->getValues();
44-
$values = empty($element->getValue()) ? [] : explode(',', $element->getValue()); // store as CSV in config
45-
46-
foreach ($options as $option) {
47-
$value = $option['value'];
48-
$html .= $this->getCheckboxHtml(
49-
$name,
50-
$value,
51-
in_array($value, $values),
52-
$option['label'],
53-
array_key_exists('description', $option) ? $option['description'] : ''
54-
);
55-
}
56-
57-
$html .= '</div>';
58-
return $html;
5965
}
6066

6167
protected function getCheckboxHtml(
68+
string $id,
6269
string $name,
6370
string $value,
6471
bool $checked,
@@ -68,13 +75,14 @@ protected function getCheckboxHtml(
6875
{
6976
$html = '<div class="form-group">';
7077
$html .= sprintf(
71-
'<input type="checkbox" name="%s[]" value="%s" %s />',
78+
'<input type="checkbox" id="%s" name="%s[]" value="%s" %s />',
79+
$id,
7280
$name,
7381
$value,
7482
$checked ? 'checked' : ''
7583
);
7684
$html .= '<div class="form-content">';
77-
$html .= sprintf('<label>%s</label>',$label ?? $name);
85+
$html .= sprintf('<label for="%s">%s</label>',$id, $label ?? $name);
7886
if ($description) {
7987
$html .= sprintf('<span class="description">%s</span>', $description);
8088
}

0 commit comments

Comments
 (0)