MarkupInterface.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Drupal\Component\Render;
  3. /**
  4. * Marks an object's __toString() method as returning markup.
  5. *
  6. * Objects that implement this interface will not be automatically XSS filtered
  7. * by the render system or automatically escaped by the theme engine.
  8. *
  9. * If there is any risk of the object's __toString() method returning
  10. * user-entered data that has not been filtered first, it must not be used. If
  11. * the object that implements this does not perform automatic escaping or
  12. * filtering itself, then it must be marked as "@internal". For example, Views
  13. * has the internal ViewsRenderPipelineMarkup object to provide a custom render
  14. * pipeline in order to render JSON and to fast render fields. By contrast,
  15. * FormattableMarkup and TranslatableMarkup always sanitize their output when
  16. * used correctly.
  17. *
  18. * If the object is going to be used directly in Twig templates it should
  19. * implement \Countable so it can be used in if statements.
  20. *
  21. * @see \Drupal\Component\Render\MarkupTrait
  22. * @see \Drupal\Core\Template\TwigExtension::escapeFilter()
  23. * @see \Drupal\Component\Render\FormattableMarkup
  24. * @see \Drupal\Core\StringTranslation\TranslatableMarkup
  25. * @see \Drupal\views\Render\ViewsRenderPipelineMarkup
  26. * @see twig_render_template()
  27. * @see sanitization
  28. * @see theme_render
  29. */
  30. interface MarkupInterface extends \JsonSerializable {
  31. /**
  32. * Returns markup.
  33. *
  34. * @return string
  35. * The markup.
  36. */
  37. public function __toString();
  38. }