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

  1. Create component with prop type number. i.e
    props:
      type: object
        price:
          type: number
          title: Price
    
  2. In content's "Manage display" Ui patterns formatter pass field type "decimal" to the prop type number using "[Field item] Decimal value" and save.
  3. 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

CommentFileSizeAuthor
#2 ui_patterns-3610520-markup-to-float.patch843 bytesrtkr
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rtkr created an issue. See original summary.

rtkr’s picture

StatusFileSize
new843 bytes
rtkr’s picture

Issue summary: View changes

pdureau’s picture

Thanks. We will have a look once the ticket status is changed to "Needs review"

michel.settembrino’s picture

Status: Active » Needs review
pdureau’s picture

Assigned: Unassigned » just_like_good_vibes
herved’s picture

FWIW I've opened #3611167: Escape at render, not in sources (rely on Twig autoescape), it should fix this case as well I think.

just_like_good_vibes made their first commit to this issue’s fork.

just_like_good_vibes’s picture

Status: Needs review » Reviewed & tested by the community

hello 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.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.