annotate core/lib/Drupal/Core/Template/AttributeBoolean.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Template;
Chris@0 4
Chris@0 5 use Drupal\Component\Utility\Html;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * A class that defines a type of boolean HTML attribute.
Chris@0 9 *
Chris@0 10 * Boolean HTML attributes are not attributes with values of TRUE/FALSE.
Chris@0 11 * They are attributes that if they exist in the tag, they are TRUE.
Chris@0 12 * Examples include selected, disabled, checked, readonly.
Chris@0 13 *
Chris@0 14 * To set a boolean attribute on the Attribute class, set it to TRUE.
Chris@0 15 * @code
Chris@0 16 * $attributes = new Attribute();
Chris@0 17 * $attributes['disabled'] = TRUE;
Chris@0 18 * echo '<select' . $attributes . '/>';
Chris@0 19 * // produces <select disabled>;
Chris@0 20 * $attributes['disabled'] = FALSE;
Chris@0 21 * echo '<select' . $attributes . '/>';
Chris@0 22 * // produces <select>;
Chris@0 23 * @endcode
Chris@0 24 *
Chris@0 25 * @see \Drupal\Core\Template\Attribute
Chris@0 26 */
Chris@0 27 class AttributeBoolean extends AttributeValueBase {
Chris@0 28
Chris@0 29 /**
Chris@0 30 * {@inheritdoc}
Chris@0 31 */
Chris@0 32 public function render() {
Chris@0 33 return $this->__toString();
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Implements the magic __toString() method.
Chris@0 38 */
Chris@0 39 public function __toString() {
Chris@0 40 return $this->value === FALSE ? '' : Html::escape($this->name);
Chris@0 41 }
Chris@0 42
Chris@0 43 }