diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index cebe699..f2cbc9a 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -161,6 +161,48 @@ public function addClass() { } /** + * Adds attribute or merges values on to array of existing attribute values. + * + * @param string $attribute + * Name of the Attribute. + * @param string|array $value + * Value(s) to add or merge to the given attribute. + * + * @return $this + */ + public function setAttribute($attribute, $value) { + // If attribute key exists we can set attribute. + $this->offsetSet($attribute, $value); + + return $this; + } + + /** + * Removes argument from array of existing attributes. + * + * @param string|array ... + * Attributes to remove from the attribute array. + * + * @return $this + */ + public function removeAttribute() { + $args = func_get_args(); + foreach ($args as $arg) { + // Support arrays or multiple arguments. + if (is_array($arg)) { + foreach ($arg as $value) { + unset($this->storage[$value]); + } + } + else { + unset($this->storage[$arg]); + } + } + + return $this; + } + + /** * Removes argument values from array of existing CSS classes. * * @param string|array ... 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() {