Field types¶
The type key sets the Form API element used for an attribute. These are
the types the module handles. Other element types that return a string, such
as textarea, email, or url, work like a text field.
Text field¶
The default when no options are set.
attributes:
title:
label: 'Tooltip'
Select list¶
The default when options are set. The list starts with "- Select -".
attributes:
target:
label: 'Link target'
options:
_blank: 'New window (_blank)'
_self: 'Same window (_self)'
Radios¶
attributes:
data-variant:
type: radios
options:
primary: 'Primary'
secondary: 'Secondary'
Checkboxes¶
Checked values are stored as an array and rendered space-separated, which
suits class and rel.
attributes:
rel:
type: checkboxes
options:
nofollow: 'nofollow'
noopener: 'noopener'
noreferrer: 'noreferrer'
Output with nofollow and noopener checked:
<a href="https://example.com" rel="nofollow noopener">Example</a>
Some sites report a fatal error when rendering menus with checkboxes attributes on core 10.3.5 and later, see #3483440. It did not occur in a test with core 11.4.
File upload¶
managed_file lets editors upload a file. Set upload_location to choose
where it is stored.
attributes:
data-icon:
type: managed_file
upload_location: 'public://menu-icons'
The attribute holds the file ID, not a URL. The theme has to load the file to use it.
Warning
The module does not mark uploaded files as permanent or record file usage. Drupal keeps them as temporary files and deletes them on cron after the temporary file age (six hours by default). Use this type only if you handle the file status yourself, for example in a custom form submit handler. See #3365622.