Machine Name Widget
Component ID
2703389
Component name
Machine Name Widget
Component type
module
Maintenance status
Development status
Component security advisory coverage
covered
Downloads
8025
Component created
Component changed
Component body
Widget for a Machine Name form element.
Machine Name Widget provides a field for the machine_name render element. This module does not provide a UI for configuring the widget, but rather is intended to be used by other modules (i.e. content entities).
Setup
The widget accepts the same configuration as machine_name. Simply use the type machine_name and pass the same config into settings.
Example
Here's an example from Colossal Menu:
$fields['machine_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Machine name'))
->setDescription(t('Machine name of the menu link'))
->setRequired(TRUE)
->setSetting('max_length', 255)
->addConstraint('UniqueField', [])
->setDisplayOptions('form', [
'type' => 'machine_name',
'weight' => -4,
'settings' => [
'source' => [
'title',
'widget',
0,
'value',
],
'exists' => 'Drupalcolossal_menuEntityLink::loadByMachineName',
],
]);
