Guides

DataNode extends AbstractNode
in package

FinalYes

A named piece of data attached to another node, rendered as an HTML `data-*` attribute on it.

Some of what the compiler learns about a node is not content: the index terms filed under a section are the first case. Rather than each such fact getting a property of its own on the node it describes, and a template change to write it out, it is attached as one of these with AbstractNode::addMetaData() and written by the renderDataAttributes Twig function -- so a search tool reading the rendered page (Pagefind, for one, reads data-* attributes) can find it, and a theme or extension can attach its own without touching the node class or the template.

Values are kept in the order they were added, each once. A node never holds two of these under the same name: attaching one under a name that is taken adds its values to those already there.

Table of Contents

Properties

$classes  : string[]
$options  : array<string, scalar|scalar[]|null>
$value  : TValue
$name  : string

Methods

__construct()  : mixed
addMetaData()  : void
Attaches data about this node that is not part of its content.
getClasses()  : string[]
getClassesString()  : string
getMetaData()  : array<string, DataNode>
getName()  : string
The attribute name without its "data-" prefix, e.g. "guides-index-terms".
getOption()  : mixed
getOptions()  : array<string, scalar|scalar[]|null>
getValue()  : TValue
getValues()  : array<int, string>
hasOption()  : bool
merge()  : self
These values, followed by the other's that are not among them yet.
setClasses()  : void
Normalizes class names following the rules of identifier-normalization
setValue()  : void
toString()  : string
The values the way the attribute carries them: comma-separated.
withKeepExistingOptions()  : static
Adds $options as default options without overriding any options already set.
withOptions()  : static

Properties

$options

protected array<string, scalar|scalar[]|null> $options = []

Methods

__construct()

public __construct(string $name[, string[] $values = [] ]) : mixed
Parameters
$name : string
$values : string[] = []

in any order and with repeats; kept in order, each once

addMetaData()

Attaches data about this node that is not part of its content.

public addMetaData(DataNode $data) : void

Rendered as a data-* attribute where the node's template asks for it. A name that is already taken gets the new values added to the ones it has, rather than replaced by them. DataNode

Parameters
$data : DataNode

getClasses()

public getClasses() : string[]
Return values
string[]

getClassesString()

public getClassesString() : string
Return values
string

getName()

The attribute name without its "data-" prefix, e.g. "guides-index-terms".

public getName() : string
Return values
string

getOption()

public getOption(string $name[, TType|null $default = null ]) : mixed
Parameters
$name : string
$default : TType|null = null
Tags
phpstan-return

($default is null ? mixed|null: TType|null)

getOptions()

public getOptions() : array<string, scalar|scalar[]|null>
Return values
array<string, scalar|scalar[]|null>

getValue()

public getValue() : TValue
Return values
TValue

getValues()

public getValues() : array<int, string>
Return values
array<int, string>

hasOption()

public hasOption(string $name) : bool
Parameters
$name : string
Return values
bool

merge()

These values, followed by the other's that are not among them yet.

public merge(self $other) : self
Parameters
$other : self
Return values
self

setValue()

public setValue(TValue $value) : void
Parameters
$value : TValue

toString()

The values the way the attribute carries them: comma-separated.

public toString() : string
Return values
string

withKeepExistingOptions()

Adds $options as default options without overriding any options already set.

public withKeepExistingOptions(array<string, scalar|null> $options) : static
Parameters
$options : array<string, scalar|null>
Return values
static

withOptions()

public withOptions(array<string, scalar|scalar[]|null> $options) : static
Parameters
$options : array<string, scalar|scalar[]|null>
Return values
static
On this page

Search results