diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index 4e9ea67..d3d4a45 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -39,6 +39,13 @@ public function render() { } /** + * Returns the boolean value. + */ + public function value() { + return $this->value; + } + + /** * Implements the magic __toString() method. */ public function __toString() { diff --git a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php index a8a64ab..249b79f 100644 --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -78,6 +78,11 @@ public function testSetAttribute() { $attribute = new Attribute(); $attribute->setAttribute('class', array('kitten', 'cat')); $this->assertArrayEquals(array('kitten', 'cat'), $attribute['class']->value()); + + // Test adding boolean attributes. + $attribute = new Attribute(); + $attribute['checked'] = TRUE; + $this->assertTrue($attribute['checked']->value()); } /** @@ -92,6 +97,7 @@ public function testRemoveAttribute() { 'style' => 'color: pink;', 'title' => 'kitten', 'value' => 'ostrich', + 'checked' => TRUE, ); $attribute = new Attribute($attributes); @@ -111,6 +117,10 @@ public function testRemoveAttribute() { // Multiple values in array. $attribute->removeAttribute(['title', 'value']); $this->assertEmpty((string) $attribute); + + // Boolean value. + $attribute->removeAttribute('checked'); + $this->assertEmpty($attribute['checked']); } /**