diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml index 448bb14c95..71aece6e00 100644 --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -271,6 +271,9 @@ field.widget.settings.machine_name: disable_on_edit: type: boolean label: 'Disable the machine name after initial creation' + standalone: + type: boolean + label: 'Keep the machine name live preview as its own form element' replace_pattern: type: string label: 'A regular expression (without delimiters) matching disallowed characters in the machine name' diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/MachineNameWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/MachineNameWidget.php index ca8b1825ac..4b7524e640 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/MachineNameWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/MachineNameWidget.php @@ -73,6 +73,7 @@ public static function defaultSettings() { return [ 'source_field' => '', 'disable_on_edit' => TRUE, + 'standalone' => FALSE, 'replace_pattern' => '[^a-z0-9_]+', 'replace' => '_', ] + parent::defaultSettings(); @@ -112,6 +113,12 @@ public function settingsForm(array $form, FormStateInterface $form_state) { '#default_value' => $this->getSetting('disable_on_edit'), '#description' => $this->t('Disable the machine name after the content has been saved for the first time.'), ]; + $element['standalone'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Standalone'), + '#default_value' => $this->getSetting('disable_on_edit'), + '#description' => $this->t('Keep the machine name live preview as its own form element, separated from the source field.'), + ]; $element['replace_pattern'] = [ '#type' => 'textfield', '#title' => $this->t('Replace pattern'), @@ -141,6 +148,7 @@ public function settingsSummary() { if (!empty($this->getSetting('source_field')) && isset($field_definitions[$this->getSetting('source_field')])) { $summary[] = $this->t('Source field: @source_field', ['@source_field' => $field_definitions[$this->getSetting('source_field')]->getLabel()]); $summary[] = $this->t('Disable on edit: @disable_on_edit', ['@disable_on_edit' => $this->getSetting('disable_on_edit') ? $this->t('Yes') : $this->t('No')]); + $summary[] = $this->t('Standalone: @standalone', ['@standalone' => $this->getSetting('standalone') ? $this->t('Yes') : $this->t('No')]); $summary[] = $this->t('Replace pattern: @replace_pattern', ['@replace_pattern' => $this->getSetting('replace_pattern')]); $summary[] = $this->t('Replace character: @replace', ['@replace' => $this->getSetting('replace')]); } @@ -169,6 +177,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // the 'UniqueField' constraint on the field that uses this widget. 'exists' => [$this, 'existsCallback'], 'label' => $this->fieldDefinition->getLabel(), + 'standalone' => $this->getSetting('standalone'), 'replace_pattern' => $this->getSetting('replace_pattern'), 'replace' => $this->getSetting('replace'), ],