Skip to content

Trait reference

Most setters on kits come from small traits in src/Kits/Traits/. A kit class composes the traits it needs, so the setters available on a kit are exactly the traits it (or a parent class) uses. Each setter writes one parameter (#<key> in the render array) and returns the kit, so calls chain.

Some traits read a key constant from the class that uses them, for example SizeTrait::setSize() writes self::SIZE_KEY. A class that uses such a trait must define the constant; this is noted below. If you use these traits in your own kit, define the constant too (see Writing your own kit).

"Used directly by" lists the classes with a use statement for the trait. "Available on" lists the classes that get it from a parent class or another trait. The lists were generated from the classes in src/Kits/.

AjaxTrait

src/Kits/Traits/AjaxTrait.php.

Builds the #ajax array. setAjax($wrapper) sets both the wrapper ID and the callback; the default callback '::ajaxFormRebuild' is a method name on your form class, which this module does not provide, so define ajaxFormRebuild() on your form or pass your own callback to setAjaxCallback().

Method
getAjaxSettings(array $default = []): array
setAjaxSettings(array $array): static
setAjax(string $wrapper = 'ajax-wrapper'): static
setAjaxSetting(string $key, array\|string\|null $value): static
setAjaxCallback(string $callback = '::ajaxFormRebuild'): static
setAjaxWrapper(string $wrapper = 'ajax-wrapper'): static

Used directly by: ButtonKit

Available on (inherited or via another trait): ImageButtonKit, SubmitButtonKit

AttributesTrait

src/Kits/Traits/AttributesTrait.php.

Reads and writes the #attributes array. setAttribute($name, $value) changes one attribute and keeps the rest.

Method
getAttributes(): array
setAttributes(array $attributes): static
getAttribute(string $name): array\|string\|null
setAttribute(string $name, array\|string\|null $value): static

Used directly by: ImageButtonKit

Available on (inherited or via another trait): no other kits

ClassAttributeTrait

src/Kits/Traits/ClassAttributeTrait.php. Uses AttributesTrait.

Helpers for the class attribute: appendClass(), getClasses(), clearClasses(). Note that getClasses() returns the raw class attribute and is declared to return array, so calling it (or appendClass(), which calls it) before any class is set fails with a TypeError; call clearClasses() first.

Method
appendClass(string $class): static
getClasses(): array
clearClasses(): static

Used by: no kit in this module. It is available for your own kits.

ConfigFactoryTrait

src/Kits/Traits/ConfigFactoryTrait.php.

Not a setter trait: gives a kit read access to configuration through the config.factory service from the container (getConfig(), getConfigData()). The service is cached in a function-level static variable.

Method
getConfigFactoryService(): Drupal\Core\Config\ConfigFactoryInterface
getConfig(string $name): Drupal\Core\Config\ImmutableConfig
getConfigData(string $name): array

Used directly by: TaxonomyTermAutoCompleteKit, TaxonomyTermSelectKit

Available on (inherited or via another trait): no other kits

DefaultValueTrait

src/Kits/Traits/DefaultValueTrait.php.

Reads and writes #default_value.

Method
getDefaultValue(array\|string\|null $default = NULL): array\|string\|null
setDefaultValue(array\|string\|null $value): static

Used directly by: EmailKit, NumberKit, PasswordConfirmKit, PasswordKit, RangeKit

Available on (inherited or via another trait): ButtonKit, CheckboxKit, CheckboxesKit, ColorKit, DateKit, DateListKit, DateTimeKit, EntityAutoCompleteKit, FieldKit, FileKit, FileSizeUploadValidatorKit, HiddenKit, ImageButtonKit, ImageExtensionUploadValidatorKit, ImageKit, ImageResolutionUploadValidatorKit, NodeAutoCompleteKit, OptionKit, PathKit, RadiosKit, SearchKit, SelectKit, SubmitButtonKit, TableSelectKit, TaxonomyTermAutoCompleteKit, TaxonomyTermSelectKit, TelephoneKit, TextAreaKit, TextFieldKit, UploadValidatorKit, UrlKit, UserAutoCompleteKit, ValueKit

DescriptionTrait

src/Kits/Traits/DescriptionTrait.php.

Reads and writes #description.

Method
getDescription(?string $default = NULL): string
setDescription(string $description): static

Used directly by: CheckboxKit, CheckboxesKit, ColorKit, DateKit, DateListKit, DateTimeKit, FileKit, NodeAutoCompleteKit, NumberKit, PathKit, RadiosKit, RangeKit, SelectKit, TableSelectKit, TaxonomyTermAutoCompleteKit, TelephoneKit, TextAreaKit, TextFieldKit, UrlKit, UserAutoCompleteKit

Available on (inherited or via another trait): ImageKit, TaxonomyTermSelectKit

EntityTrait

src/Kits/Traits/EntityTrait.php.

Not a setter trait: gives a kit the entity_type.manager service (cached in a function-level static variable) and getEntityQuery($entityType).

Method
getEntityTypeManagerService(): Drupal\Core\Entity\EntityTypeManagerInterface
getEntityQuery(string $entityType, string $conjunction = 'AND'): Drupal\Core\Entity\Query\QueryInterface

Used directly by: TaxonomyTermSelectKit

Available on (inherited or via another trait): no other kits

MultipleTrait

src/Kits/Traits/MultipleTrait.php.

Writes #multiple. The using class must define MULTIPLE_KEY.

Method
setMultiple(bool $isMultiple = TRUE): static

Used directly by: FileKit

Available on (inherited or via another trait): ImageKit

OptionsTrait

src/Kits/Traits/OptionsTrait.php. Uses StringTranslationTrait.

Stores options as OptionKit objects in the public $options property; the kit's own getArray() turns them into #options. setOptions() replaces all options from a key => label array (or OptionKit objects); appendOption() adds one, from a single-entry [key => label] array or an OptionKit. The type declaration is OptionKit|array, so the string branch inside appendOption() is unreachable.

Method
setOptions(array $options): static
appendOption(Drupal\formfactorykits\Kits\Field\Common\OptionKit\|array $mixed): static

Used directly by: CheckboxesKit, RadiosKit, SelectKit

Available on (inherited or via another trait): TaxonomyTermSelectKit

PatternTrait

src/Kits/Traits/PatternTrait.php.

Writes #pattern (an HTML5 regular expression). The using class must define PATTERN_KEY.

Method
setPattern(string $pattern): static

Used directly by: EmailKit, PasswordConfirmKit, PasswordKit, TelephoneKit, UrlKit

Available on (inherited or via another trait): no other kits

PrefixTrait

src/Kits/Traits/PrefixTrait.php.

Writes #prefix.

Method
setPrefix(array\|string\|null $value): static

Used directly by: ButtonKit, ExampleKit, FieldKit

Available on (inherited or via another trait): CheckboxKit, CheckboxesKit, ColorKit, ContainerKit, DateKit, DateListKit, DateTimeKit, EmailKit, EntityAutoCompleteKit, FileKit, FileSizeUploadValidatorKit, HiddenKit, ImageButtonKit, ImageExtensionUploadValidatorKit, ImageKit, ImageResolutionUploadValidatorKit, NodeAutoCompleteKit, NumberKit, OptionKit, PasswordConfirmKit, PasswordKit, PathKit, RadiosKit, RangeKit, SearchKit, SelectKit, SubmitButtonKit, TableSelectKit, TaxonomyTermAutoCompleteKit, TaxonomyTermSelectKit, TelephoneKit, TextAreaKit, TextFieldKit, UploadValidatorKit, UrlKit, UserAutoCompleteKit, ValueKit

RequiredTrait

src/Kits/Traits/RequiredTrait.php.

Writes #required.

Method
setRequired(bool $required = TRUE): static

Used directly by: CheckboxKit, CheckboxesKit, DateKit, FileKit, RadiosKit, TextAreaKit, TextFieldKit

Available on (inherited or via another trait): ImageKit, PathKit

SizeTrait

src/Kits/Traits/SizeTrait.php.

Writes #size. The using class must define SIZE_KEY.

Method
setSize(int $size): static

Used directly by: EmailKit, FileKit, PasswordConfirmKit, PasswordKit, TelephoneKit, TextFieldKit, UrlKit

Available on (inherited or via another trait): PathKit

StickyTrait

src/Kits/Traits/StickyTrait.php.

Writes #sticky => TRUE (sticky table header). It takes no argument and cannot turn the header off.

Method
setSticky(): static

Used directly by: TableKit, TableSelectKit

Available on (inherited or via another trait): no other kits

SuffixTrait

src/Kits/Traits/SuffixTrait.php.

Writes #suffix.

Method
setSuffix(array\|string\|null $value): static

Used directly by: ButtonKit, ExampleKit, FieldKit

Available on (inherited or via another trait): CheckboxKit, CheckboxesKit, ColorKit, ContainerKit, DateKit, DateListKit, DateTimeKit, EmailKit, EntityAutoCompleteKit, FileKit, FileSizeUploadValidatorKit, HiddenKit, ImageButtonKit, ImageExtensionUploadValidatorKit, ImageKit, ImageResolutionUploadValidatorKit, NodeAutoCompleteKit, NumberKit, OptionKit, PasswordConfirmKit, PasswordKit, PathKit, RadiosKit, RangeKit, SearchKit, SelectKit, SubmitButtonKit, TableSelectKit, TaxonomyTermAutoCompleteKit, TaxonomyTermSelectKit, TelephoneKit, TextAreaKit, TextFieldKit, UploadValidatorKit, UrlKit, UserAutoCompleteKit, ValueKit

ThemeTrait

src/Kits/Traits/ThemeTrait.php.

Writes #theme. The using class must define THEME_KEY.

Method
setTheme(string $theme): static

Used directly by: ImageKit

Available on (inherited or via another trait): no other kits

TitleTrait

src/Kits/Traits/TitleTrait.php.

Reads and writes #title. setTitle() takes a string; see the note on translatable titles in Altering any $form array.

Method
getTitle(?string $default = NULL): ?string
setTitle(string $title): static

Used directly by: CheckboxKit, CheckboxesKit, ColorKit, DateKit, DateListKit, DateTimeKit, DetailsKit, FileKit, NodeAutoCompleteKit, NumberKit, OptionKit, PathKit, RadiosKit, RangeKit, SearchKit, SelectKit, TableSelectKit, TaxonomyTermAutoCompleteKit, TelephoneKit, TextAreaKit, TextFieldKit, UserAutoCompleteKit

Available on (inherited or via another trait): ImageKit, TabKit, TaxonomyTermSelectKit

ValueTrait

src/Kits/Traits/ValueTrait.php. Uses DefaultValueTrait.

Reads and writes #value, and pulls in DefaultValueTrait. Every FieldKit has it.

Method
getValue(?string $default = NULL): array\|string\|null
setValue(array\|string\|null $value): static

Used directly by: ButtonKit, FieldKit

Available on (inherited or via another trait): CheckboxKit, CheckboxesKit, ColorKit, DateKit, DateListKit, DateTimeKit, EmailKit, EntityAutoCompleteKit, FileKit, FileSizeUploadValidatorKit, HiddenKit, ImageButtonKit, ImageExtensionUploadValidatorKit, ImageKit, ImageResolutionUploadValidatorKit, NodeAutoCompleteKit, NumberKit, OptionKit, PasswordConfirmKit, PasswordKit, PathKit, RadiosKit, RangeKit, SearchKit, SelectKit, SubmitButtonKit, TableSelectKit, TaxonomyTermAutoCompleteKit, TaxonomyTermSelectKit, TelephoneKit, TextAreaKit, TextFieldKit, UploadValidatorKit, UrlKit, UserAutoCompleteKit, ValueKit

WrapTrait

src/Kits/Traits/WrapTrait.php. Uses PrefixTrait, SuffixTrait.

wrap($id = NULL) surrounds the element with <div id="…"> using #prefix/#suffix. The default ID is <kit id>-wrapper, which matches the default of AjaxTrait::setAjaxWrapper() only when the kit ID is ajax. Pulls in PrefixTrait and SuffixTrait.

Method
wrap(?string $id = NULL): static

Used directly by: ContainerKit

Available on (inherited or via another trait): no other kits