3 namespace Drupal\Core\Template;
5 use Drupal\Component\Utility\Html;
8 * A class that defines a type of boolean HTML attribute.
10 * Boolean HTML attributes are not attributes with values of TRUE/FALSE.
11 * They are attributes that if they exist in the tag, they are TRUE.
12 * Examples include selected, disabled, checked, readonly.
14 * To set a boolean attribute on the Attribute class, set it to TRUE.
16 * $attributes = new Attribute();
17 * $attributes['disabled'] = TRUE;
18 * echo '<select' . $attributes . '/>';
19 * // produces <select disabled>;
20 * $attributes['disabled'] = FALSE;
21 * echo '<select' . $attributes . '/>';
22 * // produces <select>;
25 * @see \Drupal\Core\Template\Attribute
27 class AttributeBoolean extends AttributeValueBase {
32 public function render() {
33 return $this->__toString();
37 * Implements the magic __toString() method.
39 public function __toString() {
40 return $this->value === FALSE ? '' : Html::escape($this->name);