Problem/Motivation
When I use "[Field item] Decimal value" for the components prop type "number" I'm getting:
Warning: Object of class Drupal\Core\Render\Markup could not be converted to float in Drupal\ui_patterns\Plugin\UiPatterns\PropType\NumberPropType::normalize() (line 60 of modules/contrib/ui_patterns/src/Plugin/UiPatterns/PropType/NumberPropType.php).
which results displaying incorrect value === 1.
Steps to reproduce
- Create component with prop type number. i.e
props:
type: object
price:
type: number
title: Price
- In content's "Manage display" Ui patterns formatter pass field type "decimal" to the prop type number using "[Field item] Decimal value" and save.
- Warning is displayed with incorrect value (1)
Proposed resolution
In \Drupal\ui_patterns\Plugin\UiPatterns\PropType\NumberPropType::normalize
add this condition to cover MarkupInterface value's type
use Drupal\Component\Render\MarkupInterface;
...
if ($value instanceof MarkupInterface) {
$value = $value->__toString();
}
Remaining tasks
n/a
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Comments
Comment #2
rtkr commentedComment #3
rtkr commentedComment #5
pdureau commentedThanks. We will have a look once the ticket status is changed to "Needs review"
Comment #6
michel.settembrino commentedComment #7
pdureau commentedComment #8
herved commentedFWIW I've opened #3611167: Escape at render, not in sources (rely on Twig autoescape), it should fix this case as well I think.
Comment #10
just_like_good_vibeshello all, thank you for reporting and suggesting code fixes.
This is needed independently of the escaping-location discussion in #3611167: Escape at render, not in sources (rely on Twig autoescape).
i updated some tests.
Comment #12
just_like_good_vibes