Skip to content

Commit

Permalink
minor #6365 Tweaked the feature that allows to render HTML contents i…
Browse files Browse the repository at this point in the history
…n associations (javiereguiluz)

This PR was merged into the 4.x branch.

Discussion
----------

Tweaked the feature that allows to render HTML contents in associations

This continues #6090 and renames a method to match the naming used in other fields.

Commits
-------

70122a8 Tweaked the feature that allows to render HTML contents in associations
  • Loading branch information
javiereguiluz committed Jul 12, 2024
2 parents d92ca29 + 70122a8 commit 3f78882
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doc/fields/AssociationField.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ pass the fully-qualified class name of the controller as the first argument::
CategoryCrudController::class, 'create_category_inside_an_article', 'edit_category_inside_an_article'
);

``renderAsHtml``
~~~~~~~~~~~~~~~~

By default, the HTML contents of the items displayed in the select lists are
escaped to avoid security issues like `XSS`_. If you need to render custom HTML
contents and you are certain that they are safe to display "as is", set this
option to not escape those contents::

yield AssociationField::new('...')->renderAsHtml();

``setCrudController``
~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -146,3 +156,4 @@ associated entity::
.. _`EntityType`: https://symfony.com/doc/current/reference/forms/types/entity.html
.. _`query_builder option`: https://symfony.com/doc/current/reference/forms/types/entity.html#query-builder
.. _`value object`: https://en.wikipedia.org/wiki/Value_object
.. _`XSS`: https://en.wikipedia.org/wiki/Cross-site_scripting
4 changes: 2 additions & 2 deletions src/Field/AssociationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public function setSortProperty(string $orderProperty): self
return $this;
}

public function escapeHtml(bool $escape = true): self
public function renderAsHtml(bool $asHtml = true): self
{
$this->setCustomOption(self::OPTION_ESCAPE_HTML_CONTENTS, $escape);
$this->setCustomOption(self::OPTION_ESCAPE_HTML_CONTENTS, !$asHtml);

return $this;
}
Expand Down

0 comments on commit 3f78882

Please sign in to comment.