Skip to content

Commit 782b319

Browse files
authored
BaseControl: labels are translated using form's translator (BC Break) (#58) (#141)
1 parent 49441bf commit 782b319

9 files changed

+18
-16
lines changed

src/Forms/Controls/BaseControl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ public function getLabel($caption = NULL)
288288
{
289289
$label = clone $this->label;
290290
$label->for = $this->getHtmlId();
291-
$label->setText($this->translate($caption === NULL ? $this->caption : $caption));
291+
$caption = $caption === NULL ? $this->caption : $caption;
292+
$translator = $this->getForm()->getTranslator();
293+
$label->setText($translator ? $translator->translate($caption) : $caption);
292294
return $label;
293295
}
294296

tests/Forms/Controls.Checkbox.render.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test(function () { // Html with translator
4949
$input = $form->addCheckbox('on', 'Label');
5050
$input->setTranslator(new Translator);
5151

52-
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on">LABEL</label>', (string) $input->getControl());
52+
Assert::same('<label for="frm-on"><input type="checkbox" name="on" id="frm-on">Label</label>', (string) $input->getControl());
5353
});
5454

5555

tests/Forms/Controls.CheckboxList.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ test(function () { // translator
6464
]);
6565
$input->setTranslator(new Translator);
6666

67-
Assert::same('<label>LABEL</label>', (string) $input->getLabel());
68-
Assert::same('<label>ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
67+
Assert::same('<label>Label</label>', (string) $input->getLabel());
68+
Assert::same('<label>Another label</label>', (string) $input->getLabel('Another label'));
6969
Assert::same('<label for="frm-list-0">SECOND</label>', (string) $input->getLabelPart(0));
7070

7171
Assert::same('<label><input type="checkbox" name="list[]" value="a">FIRST</label><br><label><input type="checkbox" name="list[]" value="0">SECOND</label>', (string) $input->getControl());

tests/Forms/Controls.MultiSelectBox.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ test(function () { // translator & groups
6969
]);
7070
$input->setTranslator(new Translator);
7171

72-
Assert::same('<label for="frm-list">LABEL</label>', (string) $input->getLabel());
73-
Assert::same('<label for="frm-list">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
72+
Assert::same('<label for="frm-list">Label</label>', (string) $input->getLabel());
73+
Assert::same('<label for="frm-list">Another label</label>', (string) $input->getLabel('Another label'));
7474
Assert::same('<select name="list[]" id="frm-list" multiple><option value="a">FIRST</option><optgroup label="GROUP"><option value="0">SECOND</option><option value="1">THIRD</option></optgroup></select>', (string) $input->getControl());
7575
});
7676

tests/Forms/Controls.RadioList.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ test(function () { // translator
6464
]);
6565
$input->setTranslator(new Translator);
6666

67-
Assert::same('<label>LABEL</label>', (string) $input->getLabel());
68-
Assert::same('<label>ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
67+
Assert::same('<label>Label</label>', (string) $input->getLabel());
68+
Assert::same('<label>Another label</label>', (string) $input->getLabel('Another label'));
6969
Assert::same('<label for="frm-list-0">SECOND</label>', (string) $input->getLabelPart(0));
7070

7171
Assert::same('<label><input type="radio" name="list" value="a">FIRST</label><br><label><input type="radio" name="list" value="0">SECOND</label>', (string) $input->getControl());

tests/Forms/Controls.SelectBox.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ test(function () { // translator & groups
6969
])->setPrompt('Prompt');
7070
$input->setTranslator(new Translator);
7171

72-
Assert::same('<label for="frm-list">LABEL</label>', (string) $input->getLabel());
73-
Assert::same('<label for="frm-list">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
72+
Assert::same('<label for="frm-list">Label</label>', (string) $input->getLabel());
73+
Assert::same('<label for="frm-list">Another label</label>', (string) $input->getLabel('Another label'));
7474
Assert::same('<select name="list" id="frm-list"><option value="">PROMPT</option><option value="a">FIRST</option><optgroup label="GROUP"><option value="0">SECOND</option><option value="1">THIRD</option></optgroup></select>', (string) $input->getControl());
7575
});
7676

tests/Forms/Controls.TextArea.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ test(function () { // translator
4545
->setValue('text')
4646
->setTranslator(new Translator);
4747

48-
Assert::same('<label for="frm-text">LABEL</label>', (string) $input->getLabel());
49-
Assert::same('<label for="frm-text">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
48+
Assert::same('<label for="frm-text">Label</label>', (string) $input->getLabel());
49+
Assert::same('<label for="frm-text">Another label</label>', (string) $input->getLabel('Another label'));
5050
Assert::same('<textarea name="text" placeholder="PLACE" id="frm-text">text</textarea>', (string) $input->getControl());
5151
});
5252

tests/Forms/Controls.TextInput.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ test(function () { // translator
4646
->setTranslator(new Translator)
4747
->setEmptyValue('xxx');
4848

49-
Assert::same('<label for="frm-text">LABEL</label>', (string) $input->getLabel());
50-
Assert::same('<label for="frm-text">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
49+
Assert::same('<label for="frm-text">Label</label>', (string) $input->getLabel());
50+
Assert::same('<label for="frm-text">Another label</label>', (string) $input->getLabel('Another label'));
5151
Assert::same('<input type="text" name="text" placeholder="PLACE" id="frm-text" data-nette-empty-value="XXX" value="text">', (string) $input->getControl());
5252
});
5353

tests/Forms/Controls.UploadControl.render.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ test(function () { // Html with translator
4949
$input = $form->addUpload('file', 'Label');
5050
$input->setTranslator(new Translator);
5151

52-
Assert::same('<label for="frm-file">LABEL</label>', (string) $input->getLabel());
53-
Assert::same('<label for="frm-file">ANOTHER LABEL</label>', (string) $input->getLabel('Another label'));
52+
Assert::same('<label for="frm-file">Label</label>', (string) $input->getLabel());
53+
Assert::same('<label for="frm-file">Another label</label>', (string) $input->getLabel('Another label'));
5454
Assert::same('<label for="frm-file"><b>Another label</b></label>', (string) $input->getLabel(Html::el('b', 'Another label')));
5555
});
5656

0 commit comments

Comments
 (0)