-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reducing the complexity of view helpers #259
Conversation
protected function translateLabel(string|int $label): string|int | ||
protected function translateLabel(string $label): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fix psalm issues in #260
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason int was allowed in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #256 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing 'int' causes a BC Break. For example, if we want to generate pagination and we use only numbers:
$value = 10;
/** @var \Laminas\Form\Element\Select $field */
$field = $this->get('items_per_page');
$values = [];
for ($i = 1; $i < 4; $i++) {
$val = $i * $value;
$values[$val] = $val;
}
$field->setValueOptions($values);
Error message:
Laminas\Form\View\Helper\AbstractHelper::translateLabel(): Argument # 1 ($label) must be of type string, int given, called in .../laminas/laminas-form/src/View/Helper/FormSelect.php on line 201
laminas-form/src/View/Helper/FormSelect.php
Line 201 in ffdf00a
$label = $this->translateLabel($label); |
The solution is the need to always remember to cast all values to string:
$values[$val] = (string) $val;
Shouldn't this change be accompanied by a change: #256?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with you here. A (string)
cast should be used for all calls, or translateLabel
should be altered to accept scalar
and perform the cast there.
Conversely, all labels
should be string values regardless, so I do think it's up to the user to convert labels to strings first, but that doesn't stop this from being a BC break based on existing behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #261
Signed-off-by: Thomas Müller <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>
@mimmi20 github having incident currently. You might want to wait until problem is resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed with split-diff and hidden-whitespaces: LGTM
Signed-off-by: Thomas Müller <[email protected]>
if ($label === '' || $type === 'hidden') { | ||
return $elementString . $elementErrors; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to note.
This and following parts lost conditional for $this->renderErrors
.
Behavior remains correct because $elementErrors
is an empty string with render errors checked at line 155 that is not part of the diff.
@mimmi20 thank you |
Description
This PR wants to reduce the complexity of the
FormCollection
and theFormRow
View Helpers. Also an psalm issue is fixed.