HasPrefixCollection
API reference › HTML Mixin › HasPrefixCollection
Provides an immutable API for managing prefix element and its attributes.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$prefix protected | string | Prefix content string assigned to the element. Default: ''. | HasPrefixCollection |
$prefixAttributes protected | array | HTML attributes array for the prefix element. Default: []. | HasPrefixCollection |
$prefixTag protected | false|UnitEnum | Tag name for the prefix element, or false to disable. Default: false. | HasPrefixCollection |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
getPrefix() | Returns the prefix content string assigned to the element. | HasPrefixCollection |
getPrefixAttribute() | Returns the value of a single HTML attribute for the prefix element attributes. | HasPrefixCollection |
getPrefixAttributes() | Returns the array of HTML attributes for the prefix element. | HasPrefixCollection |
getPrefixTag() | Returns the tag name for the prefix element. | HasPrefixCollection |
prefix() | Sets the prefix content string for the element. | HasPrefixCollection |
prefixAttributes() | Sets the HTML attributes for the prefix element. | HasPrefixCollection |
prefixClass() | Adds a CSS class to the prefix element attributes. | HasPrefixCollection |
prefixRemoveAttribute() | Removes a specific HTML attribute from the prefix element. | HasPrefixCollection |
prefixSetAttribute() | Sets a single HTML attribute for the prefix element. | HasPrefixCollection |
prefixTag() | Sets the tag name for the prefix element. | HasPrefixCollection |
Method details
Section titled “Method details”getPrefix()
Section titled “getPrefix() ”public function getPrefix(): stringReturns the prefix content string assigned to the element.
Returns
string: Prefix content string assigned to the element.
getPrefixAttribute()
Section titled “getPrefixAttribute() ”public function getPrefixAttribute(string|UnitEnum $key, mixed $default = null, string $prefix = ''): mixedReturns the value of a single HTML attribute for the prefix element attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Attribute name. |
$default | mixed | Default value when the attribute is missing. |
$prefix | string | Prefix to ensure (for example, aria-, data-, on). |
Returns
mixed: Attribute value or default.
getPrefixAttributes()
Section titled “getPrefixAttributes() ”public function getPrefixAttributes(): arrayReturns the array of HTML attributes for the prefix element.
Returns
array: Attributes array assigned to the prefix element.
getPrefixTag()
Section titled “getPrefixTag() ”public function getPrefixTag(): false|UnitEnumReturns the tag name for the prefix element.
Returns
false|UnitEnum: Tag name for the prefix element, or false to disable.
prefix()
Section titled “prefix() ”public function prefix(string|Stringable ...$values): staticSets the prefix content string for the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
...$values | string|Stringable | Prefix content to set for the element. |
Returns
static: New instance with the updated prefix value.
prefixAttributes()
Section titled “prefixAttributes() ”public function prefixAttributes(array $values, string $prefix = ''): staticSets the HTML attributes for the prefix element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | array | Associative array of attribute keys and values. |
$prefix | string | Prefix to ensure (for example, aria-, data-, on). |
Returns
static: New instance with the updated prefixAttributes value.
prefixClass()
Section titled “prefixClass() ”public function prefixClass(string|Stringable|UnitEnum|null $value, bool $override = false): staticAdds a CSS class to the prefix element attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | CSS class name to add. |
$override | bool | Whether to override existing class value. |
Returns
static: New instance with the updated prefixAttributes value.
prefixRemoveAttribute()
Section titled “prefixRemoveAttribute() ”public function prefixRemoveAttribute(string|UnitEnum $key, string $prefix = ''): staticRemoves a specific HTML attribute from the prefix element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Attribute name to remove. |
$prefix | string | Prefix to ensure (for example, aria-, data-, on). |
Returns
static: New instance without the specified prefix attribute.
prefixSetAttribute()
Section titled “prefixSetAttribute() ”public function prefixSetAttribute(string|UnitEnum $key, mixed $value, string $prefix = ''): staticSets a single HTML attribute for the prefix element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Attribute name. |
$value | mixed | Attribute value. |
$prefix | string | Prefix to ensure (for example, aria-, data-, on). |
Returns
static: New instance with the updated prefixAttributes value.
prefixTag()
Section titled “prefixTag() ”public function prefixTag(false|UnitEnum $value = false): staticSets the tag name for the prefix element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | false|UnitEnum | Tag name for the prefix element, or false to disable. |
Returns
static: New instance with the updated prefixTag value.