Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[TwigBridge] Fix rendering of currency by MoneyType #26663

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

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[TwigBridge] Add html_entities filter
  • Loading branch information
ro0NL committed Mar 27, 2018
commit 0a9438369a868e963ddcaa2c13f856bc432acb4f
8 changes: 8 additions & 0 deletions 8 src/Symfony/Bridge/Twig/Extension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function getFilters()
{
return array(
new TwigFilter('humanize', array($this, 'humanize')),
new TwigFilter('form_html_entities', array($this, 'htmlEntities'), array('is_safe' => array('html'), 'needs_environment' => true)),
);
}

Expand Down Expand Up @@ -126,6 +127,13 @@ public function humanize($text)
return $this->renderer->humanize($text);
}

public function htmlEntities(Environment $environment, $text)
{
$text = htmlentities($text, ENT_QUOTES | (defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');

return iconv('UTF-8', $environment->getCharset(), $text);
}

/**
* Returns whether a choice is selected for a given form value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
{% if prepend or append %}
<div class="input-group">
{% if prepend %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-addon">{{ money_pattern|form_html_entities|replace({ '{{ widget }}':''})|raw }}</span>
{% endif %}
{{- block('form_widget_simple') -}}
{% if append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-addon">{{ money_pattern|form_html_entities|replace({ '{{ widget }}':''})|raw }}</span>
{% endif %}
</div>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
{%- endblock integer_widget -%}

{%- block money_widget -%}
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
{{ money_pattern|html_entities|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
{%- endblock money_widget -%}

{%- block url_widget -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), htmlentities($money_pattern, ENT_QUOTES | (defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8')) ?>
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getName()
}

/**
* Returns the pattern for this locale.
* Returns the pattern for this locale in UTF-8.
*
* The pattern contains the placeholder "{{ widget }}" where the HTML tag should
* be inserted
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.