class AttributeString in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Template/AttributeString.php \Drupal\Core\Template\AttributeString
- 10 core/lib/Drupal/Core/Template/AttributeString.php \Drupal\Core\Template\AttributeString
A class that represents most standard HTML attributes.
To use with the Attribute class, set the key to be the attribute name and the value the attribute value.
$attributes = new Attribute(array());
$attributes['id'] = 'socks';
$attributes['style'] = 'background-color:white';
echo '<cat ' . $attributes . '>';
// Produces: <cat id="socks" style="background-color:white">.Hierarchy
- class \Drupal\Core\Template\AttributeValueBase- class \Drupal\Core\Template\AttributeString
 
Expanded class hierarchy of AttributeString
See also
\Drupal\Core\Template\Attribute
1 file declares its use of AttributeString
- AttributeTest.php in core/tests/ Drupal/ Tests/ Core/ Template/ AttributeTest.php 
File
- core/lib/ Drupal/ Core/ Template/ AttributeString.php, line 22 
Namespace
Drupal\Core\TemplateView source
class AttributeString extends AttributeValueBase {
  /**
   * Implements the magic __toString() method.
   */
  public function __toString() {
    return Html::escape($this->value);
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| AttributeString:: | public | function | Implements the magic __toString() method. Overrides AttributeValueBase:: | |
| AttributeValueBase:: | protected | property | The name of the value. | |
| AttributeValueBase:: | protected | property | The value itself. | |
| AttributeValueBase:: | public | function | Returns a string representation of the attribute. | 1 | 
| AttributeValueBase:: | constant | Renders '$name=""' if $value is an empty string. | 1 | |
| AttributeValueBase:: | public | function | Returns the raw value. | |
| AttributeValueBase:: | public | function | Constructs a \Drupal\Core\Template\AttributeValueBase object. | 
