class DrupalAttributes in Express 8
Class for managing multiple types of attributes commonly found in Drupal.
Hierarchy
- class \Drupal\bootstrap\Utility\ArrayObject implements \Drupal\bootstrap\Utility\IteratorAggregate, \Drupal\bootstrap\Utility\ArrayAccess, \Drupal\bootstrap\Utility\Serializable, \Drupal\bootstrap\Utility\Countable, RefinableCacheableDependencyInterface, AttachmentsInterface
- class \Drupal\bootstrap\Utility\DrupalAttributes
Expanded class hierarchy of DrupalAttributes
See also
\Drupal\bootstrap\Utility\Attributes
\Drupal\bootstrap\Utility\Element
\Drupal\bootstrap\Utility\Variables
File
- themes/
contrib/ bootstrap/ src/ Utility/ DrupalAttributes.php, line 20 - Contains \Drupal\bootstrap\Utility\DrupalAttributes.
Namespace
Drupal\bootstrap\UtilityView source
class DrupalAttributes extends ArrayObject {
/**
* Defines the "attributes" storage type constant.
*
* @var string
*/
const ATTRIBUTES = 'attributes';
/**
* Defines the "body_attributes" storage type constant.
*
* @var string
*/
const BODY = 'body_attributes';
/**
* Defines the "content_attributes" storage type constant.
*
* @var string
*/
const CONTENT = 'content_attributes';
/**
* Defines the "description_attributes" storage type constant.
*
* @var string
*/
const DESCRIPTION = 'description_attributes';
/**
* Defines the "footer_attributes" storage type constant.
*
* @var string
*/
const FOOTER = 'footer_attributes';
/**
* Defines the "header_attributes" storage type constant.
*
* @var string
*/
const HEADER = 'header_attributes';
/**
* Defines the "heading_attributes" storage type constant.
*
* @var string
*/
const HEADING = 'heading_attributes';
/**
* Defines the "input_group_attributes" storage type constant.
*
* @var string
*/
const INPUT_GROUP = 'input_group_attributes';
/**
* Defines the "label_attributes" storage type constant.
*
* @var string
*/
const LABEL = 'label_attributes';
/**
* Defines the "navbar_attributes" storage type constant.
*
* @var string
*/
const NAVBAR = 'navbar_attributes';
/**
* Defines the "split_button_attributes" storage type constant.
*
* @var string
*/
const SPLIT_BUTTON = 'split_button_attributes';
/**
* Defines the "title_attributes" storage type constant.
*
* @var string
*/
const TITLE = 'title_attributes';
/**
* Defines the "wrapper_attributes" storage type constant.
*
* @var string
*/
const WRAPPER = 'wrapper_attributes';
/**
* Stored attribute instances.
*
* @var \Drupal\bootstrap\Utility\Attributes[]
*/
protected $attributes = [];
/**
* A prefix to use for retrieving attribute keys from the array.
*
* @var string
*/
protected $attributePrefix = '';
/**
* Add class(es) to an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then add the class(es) to it.
*
* @param string|array $class
* An individual class or an array of classes to add.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return $this
*
* @see \Drupal\bootstrap\Utility\Attributes::addClass()
*/
public function addClass($class, $type = DrupalAttributes::ATTRIBUTES) {
$this
->getAttributes($type)
->addClass($class);
return $this;
}
/**
* Retrieve a specific attribute from an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then retrieve the attribute from it.
*
* @param string $name
* The specific attribute to retrieve.
* @param mixed $default
* (optional) The default value to set if the attribute does not exist.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return mixed
* A specific attribute value, passed by reference.
*
* @see \Drupal\bootstrap\Utility\Attributes::getAttribute()
*/
public function &getAttribute($name, $default = NULL, $type = DrupalAttributes::ATTRIBUTES) {
return $this
->getAttributes($type)
->getAttribute($name, $default);
}
/**
* Retrieves a specific attributes object.
*
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return \Drupal\bootstrap\Utility\Attributes
* An attributes object for $type.
*/
public function getAttributes($type = DrupalAttributes::ATTRIBUTES) {
if (!isset($this->attributes[$type])) {
$attributes =& $this
->offsetGet($this->attributePrefix . $type, []);
if ($attributes instanceof Attribute) {
$attributes = $attributes
->toArray();
}
$this->attributes[$type] = new Attributes($attributes);
}
return $this->attributes[$type];
}
/**
* Retrieves classes from an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then retrieve the set classes from it.
*
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return array
* The classes array, passed by reference.
*
* @see \Drupal\bootstrap\Utility\Attributes::getClasses()
*/
public function &getClasses($type = DrupalAttributes::ATTRIBUTES) {
return $this
->getAttributes($type)
->getClasses();
}
/**
* Indicates whether an attributes object has a specific attribute set.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then check there if the attribute exists.
*
* @param string $name
* The attribute to search for.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return bool
* TRUE or FALSE
*
* @see \Drupal\bootstrap\Utility\Attributes::hasAttribute()
*/
public function hasAttribute($name, $type = DrupalAttributes::ATTRIBUTES) {
return $this
->getAttributes($type)
->hasAttribute($name);
}
/**
* Indicates whether an attributes object has a specific class.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then check there if a class exists in the attributes object.
*
* @param string $class
* The class to search for.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return bool
* TRUE or FALSE
*
* @see \Drupal\bootstrap\Utility\Attributes::hasClass()
*/
public function hasClass($class, $type = DrupalAttributes::ATTRIBUTES) {
return $this
->getAttributes($type)
->hasClass($class);
}
/**
* Removes an attribute from an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then remove an attribute from it.
*
* @param string|array $name
* The name of the attribute to remove.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return $this
*
* @see \Drupal\bootstrap\Utility\Attributes::removeAttribute()
*/
public function removeAttribute($name, $type = DrupalAttributes::ATTRIBUTES) {
$this
->getAttributes($type)
->removeAttribute($name);
return $this;
}
/**
* Removes a class from an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then remove the class(es) from it.
*
* @param string|array $class
* An individual class or an array of classes to remove.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return $this
*
* @see \Drupal\bootstrap\Utility\Attributes::removeClass()
*/
public function removeClass($class, $type = DrupalAttributes::ATTRIBUTES) {
$this
->getAttributes($type)
->removeClass($class);
return $this;
}
/**
* Replaces a class in an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then replace the class(es) in it.
*
* @param string $old
* The old class to remove.
* @param string $new
* The new class. It will not be added if the $old class does not exist.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return $this
*
* @see \Drupal\bootstrap\Utility\Attributes::replaceClass()
*/
public function replaceClass($old, $new, $type = DrupalAttributes::ATTRIBUTES) {
$this
->getAttributes($type)
->replaceClass($old, $new);
return $this;
}
/**
* Sets an attribute on an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then set an attribute on it.
*
* @param string $name
* The name of the attribute to set.
* @param mixed $value
* The value of the attribute to set.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return $this
*
* @see \Drupal\bootstrap\Utility\Attributes::setAttribute()
*/
public function setAttribute($name, $value, $type = DrupalAttributes::ATTRIBUTES) {
$this
->getAttributes($type)
->setAttribute($name, $value);
return $this;
}
/**
* Sets multiple attributes on an attributes object.
*
* This is a wrapper method to retrieve the correct attributes storage object
* and then merge multiple attributes into it.
*
* @param array $values
* An associative key/value array of attributes to set.
* @param string $type
* (optional) The type of attributes to use for this method.
*
* @return $this
*
* @see \Drupal\bootstrap\Utility\Attributes::setAttributes()
*/
public function setAttributes(array $values, $type = DrupalAttributes::ATTRIBUTES) {
$this
->getAttributes($type)
->setAttributes($values);
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ArrayObject:: |
protected | property | The array. | |
ArrayObject:: |
public | function |
Adds attachments. Overrides AttachmentsInterface:: |
|
ArrayObject:: |
public | function |
Adds a dependency on an object: merges its cacheability metadata. Overrides RefinableCacheableDependencyInterface:: |
|
ArrayObject:: |
public | function |
Adds cache contexts. Overrides RefinableCacheableDependencyInterface:: |
|
ArrayObject:: |
public | function |
Adds cache tags. Overrides RefinableCacheableDependencyInterface:: |
|
ArrayObject:: |
public | function | Appends the value. | |
ArrayObject:: |
public | function | Sort the entries by value. | |
ArrayObject:: |
public | function | Merges an object's cacheable metadata into the variables array. | |
ArrayObject:: |
public | function | Merges a render array's cacheable metadata into the variables array. | |
ArrayObject:: |
public | function | Get the number of public properties in the ArrayObject. | |
ArrayObject:: |
public | function | Exchange the array for another one. | 1 |
ArrayObject:: |
public | function | Creates a copy of the ArrayObject. | |
ArrayObject:: |
public | function |
Gets attachments. Overrides AttachmentsInterface:: |
|
ArrayObject:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
ArrayObject:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
ArrayObject:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
ArrayObject:: |
public | function | Creates a new iterator from an ArrayObject instance. | |
ArrayObject:: |
public | function | Sort the entries by key. | |
ArrayObject:: |
public | function | Merges multiple values into the array. | |
ArrayObject:: |
public | function |
Merges the maximum age (in seconds) with the existing maximum age. Overrides RefinableCacheableDependencyInterface:: |
|
ArrayObject:: |
public | function | Sort an array using a case insensitive "natural order" algorithm. | |
ArrayObject:: |
public | function | Sort entries using a "natural order" algorithm. | |
ArrayObject:: |
public | function | Returns whether the requested key exists. | |
ArrayObject:: |
public | function | Returns the value at the specified key. | |
ArrayObject:: |
public | function | Sets the value at the specified key to value. | |
ArrayObject:: |
public | function | Unsets the value at the specified key. | |
ArrayObject:: |
public | function | Serialize an ArrayObject. | |
ArrayObject:: |
public | function |
Sets attachments. Overrides AttachmentsInterface:: |
|
ArrayObject:: |
public | function | Sort entries with a user-defined function and maintain key association. | |
ArrayObject:: |
public | function | Sort the entries by keys using a user-defined comparison function. | |
ArrayObject:: |
public | function | Unserialize an ArrayObject. | |
ArrayObject:: |
public | function | Array object constructor. | 3 |
ArrayObject:: |
public | function | Returns the value at the specified key by reference. | 1 |
ArrayObject:: |
public | function | Returns whether the requested key exists. | 1 |
ArrayObject:: |
public | function | Sets the value at the specified key to value. | 1 |
ArrayObject:: |
public | function | Unsets the value at the specified key. | 1 |
DrupalAttributes:: |
protected | property | A prefix to use for retrieving attribute keys from the array. | 1 |
DrupalAttributes:: |
protected | property | Stored attribute instances. | |
DrupalAttributes:: |
public | function | Add class(es) to an attributes object. | |
DrupalAttributes:: |
constant | Defines the "attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "body_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "content_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "description_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "footer_attributes" storage type constant. | ||
DrupalAttributes:: |
public | function | Retrieve a specific attribute from an attributes object. | |
DrupalAttributes:: |
public | function | Retrieves a specific attributes object. | |
DrupalAttributes:: |
public | function | Retrieves classes from an attributes object. | |
DrupalAttributes:: |
public | function | Indicates whether an attributes object has a specific attribute set. | |
DrupalAttributes:: |
public | function | Indicates whether an attributes object has a specific class. | |
DrupalAttributes:: |
constant | Defines the "header_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "heading_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "input_group_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "label_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "navbar_attributes" storage type constant. | ||
DrupalAttributes:: |
public | function | Removes an attribute from an attributes object. | |
DrupalAttributes:: |
public | function | Removes a class from an attributes object. | |
DrupalAttributes:: |
public | function | Replaces a class in an attributes object. | |
DrupalAttributes:: |
public | function | Sets an attribute on an attributes object. | |
DrupalAttributes:: |
public | function | Sets multiple attributes on an attributes object. | |
DrupalAttributes:: |
constant | Defines the "split_button_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "title_attributes" storage type constant. | ||
DrupalAttributes:: |
constant | Defines the "wrapper_attributes" storage type constant. |