A class that defines a type of Attribute that can be added to as an array.
To use with Attribute, the array must be specified. Correct:
$attributes = new Attribute(array());
$attributes['class'] = array();
$attributes['class'][] = 'cat';
Incorrect:
$attributes = new Attribute(array());
$attributes['class'][] = 'cat';
Expanded class hierarchy of AttributeArray
Drupal\Core\Template\Attribute
class AttributeArray extends AttributeValueBase implements \ArrayAccess, \IteratorAggregate {
/**
* Implements ArrayAccess::offsetGet().
*/
public function offsetGet($offset) {
return $this->value[$offset];
}
/**
* Implements ArrayAccess::offsetSet().
*/
public function offsetSet($offset, $value) {
if (isset($offset)) {
$this->value[$offset] = $value;
}
else {
$this->value[] = $value;
}
}
/**
* Implements ArrayAccess::offsetUnset().
*/
public function offsetUnset($offset) {
unset($this->value[$offset]);
}
/**
* Implements ArrayAccess::offsetExists().
*/
public function offsetExists($offset) {
return isset($this->value[$offset]);
}
/**
* Implements the magic __toString() method.
*/
public function __toString() {
$this->printed = TRUE;
return implode(' ', array_map('check_plain', $this->value));
}
/**
* Implements IteratorAggregate::getIterator().
*/
public function getIterator() {
return new \ArrayIterator($this->value);
}
/**
* Returns the whole array.
*/
public function value() {
return $this->value;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AttributeArray:: |
public | function | Implements IteratorAggregate::getIterator(). | |
AttributeArray:: |
public | function | Implements ArrayAccess::offsetExists(). | |
AttributeArray:: |
public | function | Implements ArrayAccess::offsetGet(). | |
AttributeArray:: |
public | function | Implements ArrayAccess::offsetSet(). | |
AttributeArray:: |
public | function | Implements ArrayAccess::offsetUnset(). | |
AttributeArray:: |
public | function | Returns the whole array. | |
AttributeArray:: |
public | function |
Implements the magic __toString() method. Overrides AttributeValueBase:: |
|
AttributeValueBase:: |
protected | property | The name of the value. | |
AttributeValueBase:: |
protected | property | Whether this attribute hsa been printed already. | |
AttributeValueBase:: |
protected | property | The value itself. | |
AttributeValueBase:: |
public | function | Whether this attribute hsa been printed already. | |
AttributeValueBase:: |
public | function | Returns a string representation of the attribute. | 1 |
AttributeValueBase:: |
public | function | Constructs a \Drupal\Core\Template\AttributeValueBase object. |