AttributeString.php 742 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\Core\Template;
  3. use Drupal\Component\Utility\Html;
  4. /**
  5. * A class that represents most standard HTML attributes.
  6. *
  7. * To use with the Attribute class, set the key to be the attribute name
  8. * and the value the attribute value.
  9. * @code
  10. * $attributes = new Attribute(array());
  11. * $attributes['id'] = 'socks';
  12. * $attributes['style'] = 'background-color:white';
  13. * echo '<cat ' . $attributes . '>';
  14. * // Produces: <cat id="socks" style="background-color:white">.
  15. * @endcode
  16. *
  17. * @see \Drupal\Core\Template\Attribute
  18. */
  19. class AttributeString extends AttributeValueBase {
  20. /**
  21. * Implements the magic __toString() method.
  22. */
  23. public function __toString() {
  24. return Html::escape($this->value);
  25. }
  26. }