class Attributes in Express 8
Class to help modify attributes.
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\Attributes
Expanded class hierarchy of Attributes
File
- themes/
contrib/ bootstrap/ src/ Utility/ Attributes.php, line 14 - Contains \Drupal\bootstrap\Utility\Attributes.
Namespace
Drupal\bootstrap\UtilityView source
class Attributes extends ArrayObject {
/**
* {@inheritdoc}
*/
public function __construct(array &$array = []) {
$this->array =& $array;
}
/**
* Add class(es) to the array.
*
* @param string|array $class
* An individual class or an array of classes to add.
*
* @see \Drupal\bootstrap\Utility\Attributes::getClasses()
*/
public function addClass($class) {
$classes =& $this
->getClasses();
$classes = array_unique(array_merge($classes, (array) $class));
}
/**
* Retrieve a specific attribute from the array.
*
* @param string $name
* The specific attribute to retrieve.
* @param mixed $default
* (optional) The default value to set if the attribute does not exist.
*
* @return mixed
* A specific attribute value, passed by reference.
*
* @see \Drupal\bootstrap\Utility\ArrayObject::offsetGet()
*/
public function &getAttribute($name, $default = NULL) {
return $this
->offsetGet($name, $default);
}
/**
* Retrieves classes from the array.
*
* @return array
* The classes array, passed by reference.
*
* @see \Drupal\bootstrap\Utility\ArrayObject::offsetGet()
*/
public function &getClasses() {
$classes =& $this
->offsetGet('class', []);
$classes = array_unique($classes);
return $classes;
}
/**
* Indicates whether a specific attribute is set.
*
* @param string $name
* The attribute to search for.
*
* @return bool
* TRUE or FALSE
*
* @see \Drupal\bootstrap\Utility\ArrayObject::offsetExists()
*/
public function hasAttribute($name) {
return $this
->offsetExists($name);
}
/**
* Indicates whether a class is present in the array.
*
* @param string|array $class
* The class or array of classes to search for.
* @param bool $all
* Flag determining to check if all classes are present.
*
* @return bool
* TRUE or FALSE
*
* @see \Drupal\bootstrap\Utility\Attributes::getClasses()
*/
public function hasClass($class, $all = FALSE) {
$classes = (array) $class;
$result = array_intersect($classes, $this
->getClasses());
return $all ? $result && count($classes) === count($result) : !!$result;
}
/**
* Removes an attribute from the array.
*
* @param string|array $name
* The name of the attribute to remove.
*
* @see \Drupal\bootstrap\Utility\ArrayObject::offsetUnset()
*/
public function removeAttribute($name) {
$this
->offsetUnset($name);
}
/**
* Removes a class from the attributes array.
*
* @param string|array $class
* An individual class or an array of classes to remove.
*
* @see \Drupal\bootstrap\Utility\Attributes::getClasses()
*/
public function removeClass($class) {
$classes =& $this
->getClasses();
$classes = array_values(array_diff($classes, (array) $class));
}
/**
* Replaces a class in the attributes array.
*
* @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.
*
* @see \Drupal\bootstrap\Utility\Attributes::getClasses()
*/
public function replaceClass($old, $new) {
$classes =& $this
->getClasses();
$key = array_search($old, $classes);
if ($key !== FALSE) {
$classes[$key] = $new;
}
}
/**
* Sets an attribute on the array.
*
* @param string $name
* The name of the attribute to set.
* @param mixed $value
* The value of the attribute to set.
*
* @see \Drupal\bootstrap\Utility\ArrayObject::offsetSet()
*/
public function setAttribute($name, $value) {
$this
->offsetSet($name, $value);
}
/**
* Sets multiple attributes on the array.
*
* @param array $values
* An associative key/value array of attributes to set.
*
* @see \Drupal\bootstrap\Utility\ArrayObject::merge()
*/
public function setAttributes(array $values) {
$this
->merge($values);
}
}
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 | 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 |
Attributes:: |
public | function | Add class(es) to the array. | |
Attributes:: |
public | function | Retrieve a specific attribute from the array. | |
Attributes:: |
public | function | Retrieves classes from the array. | |
Attributes:: |
public | function | Indicates whether a specific attribute is set. | |
Attributes:: |
public | function | Indicates whether a class is present in the array. | |
Attributes:: |
public | function | Removes an attribute from the array. | |
Attributes:: |
public | function | Removes a class from the attributes array. | |
Attributes:: |
public | function | Replaces a class in the attributes array. | |
Attributes:: |
public | function | Sets an attribute on the array. | |
Attributes:: |
public | function | Sets multiple attributes on the array. | |
Attributes:: |
public | function |
Array object constructor. Overrides ArrayObject:: |