class Variables in Express 8
Class to help modify template variables.
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
- class \Drupal\bootstrap\Utility\Variables
- class \Drupal\bootstrap\Utility\DrupalAttributes
Expanded class hierarchy of Variables
25 files declare their use of Variables
- BootstrapCarousel.php in themes/
contrib/ bootstrap/ src/ Plugin/ Preprocess/ BootstrapCarousel.php - Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapCarousel.
- BootstrapDropdown.php in themes/
contrib/ bootstrap/ src/ Plugin/ Preprocess/ BootstrapDropdown.php - Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapDropdown.
- BootstrapModal.php in themes/
contrib/ bootstrap/ src/ Plugin/ Preprocess/ BootstrapModal.php - Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapModal.
- BootstrapPanel.php in themes/
contrib/ bootstrap/ src/ Plugin/ Preprocess/ BootstrapPanel.php - Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapPanel.
- Breadcrumb.php in themes/
contrib/ bootstrap/ src/ Plugin/ Preprocess/ Breadcrumb.php - Contains \Drupal\bootstrap\Plugin\Preprocess\Breadcrumb.
File
- themes/
contrib/ bootstrap/ src/ Utility/ Variables.php, line 14 - Contains \Drupal\bootstrap\Utility\Variables.
Namespace
Drupal\bootstrap\UtilityView source
class Variables extends DrupalAttributes {
/**
* An element object.
*
* @var \Drupal\bootstrap\Utility\Element|FALSE
*/
public $element = FALSE;
/**
* Element constructor.
*
* @param array $variables
* A theme hook variables array.
*/
public function __construct(array &$variables) {
$this->array =& $variables;
if (isset($variables['element']) && Element::isRenderArray($variables['element'])) {
$this->element = Element::create($variables['element']);
}
elseif (isset($variables['elements']) && Element::isRenderArray($variables['elements'])) {
$this->element = Element::create($variables['elements']);
}
}
/**
* Creates a new \Drupal\bootstrap\Utility\Variables instance.
*
* @param array $variables
* A theme hook variables array.
*
* @return \Drupal\bootstrap\Utility\Variables
* The newly created variables instance.
*/
public static function create(array &$variables) {
return new self($variables);
}
/**
* Retrieves a context value from the variables array or its element, if any.
*
* @param string $name
* The name of the context key to retrieve.
* @param mixed $default
* Optional. The default value to use if the context $name isn't set.
*
* @return mixed|NULL
* The context value or the $default value if not set.
*/
public function &getContext($name, $default = NULL) {
$context =& $this
->offsetGet($this->attributePrefix . 'context', []);
if (!isset($context[$name])) {
// If there is no context on the variables array but there is an element
// present, proxy the method to the element.
if ($this->element) {
return $this->element
->getContext($name, $default);
}
$context[$name] = $default;
}
return $context[$name];
}
/**
* Maps an element's properties to the variables attributes array.
*
* @param array $map
* An associative array whose keys are element property names and whose
* values are the variable names to set in the variables array; e.g.,
* array('#property_name' => 'variable_name'). If both names are identical
* except for the leading '#', then an attribute name value is sufficient
* and no property name needs to be specified.
* @param bool $overwrite
* If the variable exists, it will be overwritten. This does not apply to
* attribute arrays, they will always be merged recursively.
*
* @return $this
*/
public function map(array $map, $overwrite = TRUE) {
// Immediately return if there is no element in the variable array.
if (!$this->element) {
return $this;
}
// Iterate over each map item.
foreach ($map as $property => $variable) {
// If the key is numeric, the attribute name needs to be taken over.
if (is_int($property)) {
$property = $variable;
}
// Merge attributes from the element.
if (strpos($property, 'attributes') !== FALSE) {
$this
->setAttributes($this->element
->getAttributes($property)
->getArrayCopy(), $variable);
}
elseif ($overwrite || !$this
->offsetExists($variable)) {
$this
->offsetSet($variable, $this->element
->getProperty($property));
}
}
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 | 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. | ||
Variables:: |
public | property | An element object. | |
Variables:: |
public static | function | Creates a new \Drupal\bootstrap\Utility\Variables instance. | |
Variables:: |
public | function | Retrieves a context value from the variables array or its element, if any. | |
Variables:: |
public | function | Maps an element's properties to the variables attributes array. | |
Variables:: |
public | function |
Element constructor. Overrides ArrayObject:: |