#[ListOf]

Attribute on parameters and properties.

use WebCodingCat\WpAppFramework\Value\ListOf;

Declares the item type of an array parameter: a backed enum or a value class (PHP has no generics). Used in block attribute classes, value classes and REST arguments.

min and max limit the number of items editors can create. They are no schema keywords of stored values, so a stored list outside the limits is kept as it is: the editor marks it, and only its first max items are created. REST arguments validate them (minItems, maxItems).

Editors see each item as a card that they can expand, collapse and drag to sort. Its heading is the first text of the item (the label of an enum case), else itemLabel with the number of the item.

With appender, the block editor shows one more item in the canvas, empty and faded, as long as the list is below max: a click adds it. The template marks the root element of each item with list_item().

Arguments

#[ListOf(string $class, int $min = 0, ?int $max = null, ?string $itemLabel = null, bool $appender = false)]
ParameterTypeDefaultDescription
classclass-stringrequiredA backed enum or a value class.
minint0The fewest items: editors cannot remove more. 0 or more.
maxint|nullnullThe most items: editors cannot add more, and only the first max stored items are created. 1 or more and at least min; null for no limit.
itemLabelstring|nullnullWhat one item is, for the heading of an item without text, e.g. "Badge 2"; null for the short name of the class in words (SocialLink becomes "Social link").
appenderboolfalseAdd items in the canvas of the block editor through a faded new item. Only for lists of values in block attributes, not in list items.