Custom contraint validator: show an error message with a link We use a custom constraint on a custom entity type. In this entity type we have a string field &quot;url basis&quot; which is used to create aliases for many kinds of pages and data related to this entity.
Therefore it is important that this url basis is unique with every single entity. Here is the constraint:
class UniqueParliamentBasisUrl extends Constraint {
  public $notUniqueURLBasis = 'The basis URL needs to be unqiue but the set basis URL %basisurl is already in use: @parliament_link';
}

In UniqueParliamentBasisUrlValidator-&gt;validate() I try the following:
    $link = $parliament_using_basis_url-&gt;toLink($parliament_using_basis_url-&gt;label(), 'edit-form', ['attributes' =&gt; ['target' =&gt; '_blank']])-&gt;toString();
    $this-&gt;context-&gt;addViolation($constraint-&gt;notUniqueURLBasis, ['%basisurl' =&gt; $item-&gt;value, '@parliament_link' =&gt; $link]);

Here $link becomes the HTML markup for a link so that the user can easily switch to the entity which already uses this url basis in order to edit it. Unfortunately the markup becomes escaped so that the user does not see a clickable link on the form but the markup:
The basis URL needs to be unqiue but the set basis URL bundestag is already in use: &lt;a href=&quot;/admin/parliament-watch/parliaments/5/edit&quot; target=&quot;_blank&quot; hreflang=&quot;und&quot;&gt;Bundestag&lt;/a&gt;

Is there a way to add markup to the violation message without being escaped?
You shouldn't chain up placeholders / use HTML inside placeholders. And for URLs use the :placeholder notation with double dots
 $notUniqueURLBasis = 'The basis URL needs to be unqiue but the set basis URL %basisurl is already in use: &lt;a href=&quot;:existing_url&quot;&gt;@link_text&lt;/a&gt;';

See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Render%21FormattableMarkup.php/class/FormattableMarkup/8.2.x
and
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Render%21FormattableMarkup.php/function/FormattableMarkup%3A%3AplaceholderFormat/8.2.x