comparison core/lib/Drupal/Core/Template/AttributeBoolean.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Core\Template;
4
5 use Drupal\Component\Utility\Html;
6
7 /**
8 * A class that defines a type of boolean HTML attribute.
9 *
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.
13 *
14 * To set a boolean attribute on the Attribute class, set it to TRUE.
15 * @code
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>;
23 * @endcode
24 *
25 * @see \Drupal\Core\Template\Attribute
26 */
27 class AttributeBoolean extends AttributeValueBase {
28
29 /**
30 * {@inheritdoc}
31 */
32 public function render() {
33 return $this->__toString();
34 }
35
36 /**
37 * Implements the magic __toString() method.
38 */
39 public function __toString() {
40 return $this->value === FALSE ? '' : Html::escape($this->name);
41 }
42
43 }