Attribute
class Attribute implements ArrayAccess, IteratorAggregate, MarkupInterface (View source)
Collects, sanitizes, and renders HTML attributes.
To use, optionally pass in an associative array of defined attributes, or add attributes using array syntax. For example:
Properties
| protected AttributeValueBase[] | $storage | Stores the attribute data. |
Methods
Constructs a \Drupal\Core\Template\Attribute object.
{@inheritdoc}
{@inheritdoc}
Creates the different types of attribute values.
{@inheritdoc}
{@inheritdoc}
Adds classes or merges them on to array of existing CSS classes.
Sets values for an attribute key.
Checks if the storage has an attribute with the given name.
Removes an attribute from an Attribute object.
Removes argument values from array of existing CSS classes.
Gets the class attribute value if set.
Checks if the class array has the given CSS class.
Implements the magic __toString() method.
Returns all storage elements as an array.
Implements the magic __clone() method.
{@inheritdoc}
Returns the whole array.
Returns a representation of the object for use in JSON serialization.
Details
__construct(array $attributes = [])
Constructs a \Drupal\Core\Template\Attribute object.
offsetGet($name)
{@inheritdoc}
offsetSet($name, $value)
{@inheritdoc}
protected AttributeValueBase
createAttributeValue(string $name, mixed $value)
Creates the different types of attribute values.
offsetUnset($name)
{@inheritdoc}
offsetExists($name)
{@inheritdoc}
$this
addClass()
Adds classes or merges them on to array of existing CSS classes.
$this
setAttribute(string $attribute, string|array $value)
Sets values for an attribute key.
bool
hasAttribute(string $name)
Checks if the storage has an attribute with the given name.
$this
removeAttribute()
Removes an attribute from an Attribute object.
$this
removeClass()
Removes argument values from array of existing CSS classes.
AttributeValueBase
getClass()
Gets the class attribute value if set.
This method is implemented to take precedence over hasClass() for Twig 2.0.
bool
hasClass(string $class)
Checks if the class array has the given CSS class.
string
__toString()
Implements the magic __toString() method.
array
toArray()
Returns all storage elements as an array.
__clone()
Implements the magic __clone() method.
getIterator()
{@inheritdoc}
storage()
Returns the whole array.
string
jsonSerialize()
Returns a representation of the object for use in JSON serialization.
$this
merge(Attribute $collection)
Merges an Attribute object into the current storage.