Skip to content
PHP Ecosystem
Explore

HasPrefixCollection

API reference › HTML Mixin › HasPrefixCollection

traitUIAwesome\Html\Mixin\HasPrefixCollection
Sourcesrc/HasPrefixCollection.php
Used by 2 types

Provides an immutable API for managing prefix element and its attributes.

PropertyTypeDescriptionDefined by
$prefix protectedstringPrefix content string assigned to the element. Default: ''.HasPrefixCollection
$prefixAttributes protectedarrayHTML attributes array for the prefix element. Default: [].HasPrefixCollection
$prefixTag protectedfalse|UnitEnumTag name for the prefix element, or false to disable. Default: false.HasPrefixCollection
MethodDescriptionDefined 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
public function getPrefix(): string

Returns the prefix content string assigned to the element.

Returns

string: Prefix content string assigned to the element.

public function getPrefixAttribute(string|UnitEnum $key, mixed $default = null, string $prefix = ''): mixed

Returns the value of a single HTML attribute for the prefix element attributes.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAttribute name.
$defaultmixedDefault value when the attribute is missing.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Returns

mixed: Attribute value or default.

public function getPrefixAttributes(): array

Returns the array of HTML attributes for the prefix element.

Returns

array: Attributes array assigned to the prefix element.

public function getPrefixTag(): false|UnitEnum

Returns the tag name for the prefix element.

Returns

false|UnitEnum: Tag name for the prefix element, or false to disable.

public function prefix(string|Stringable ...$values): static

Sets the prefix content string for the element.

Parameters

ParameterTypeDescription
...$valuesstring|StringablePrefix content to set for the element.

Returns

static: New instance with the updated prefix value.

public function prefixAttributes(array $values, string $prefix = ''): static

Sets the HTML attributes for the prefix element.

Parameters

ParameterTypeDescription
$valuesarrayAssociative array of attribute keys and values.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Returns

static: New instance with the updated prefixAttributes value.

public function prefixClass(string|Stringable|UnitEnum|null $value, bool $override = false): static

Adds a CSS class to the prefix element attributes.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullCSS class name to add.
$overrideboolWhether to override existing class value.

Returns

static: New instance with the updated prefixAttributes value.

public function prefixRemoveAttribute(string|UnitEnum $key, string $prefix = ''): static

Removes a specific HTML attribute from the prefix element.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAttribute name to remove.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Returns

static: New instance without the specified prefix attribute.

public function prefixSetAttribute(string|UnitEnum $key, mixed $value, string $prefix = ''): static

Sets a single HTML attribute for the prefix element.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAttribute name.
$valuemixedAttribute value.
$prefixstringPrefix to ensure (for example, aria-, data-, on).

Returns

static: New instance with the updated prefixAttributes value.

public function prefixTag(false|UnitEnum $value = false): static

Sets the tag name for the prefix element.

Parameters

ParameterTypeDescription
$valuefalse|UnitEnumTag name for the prefix element, or false to disable.

Returns

static: New instance with the updated prefixTag value.