public function NameWidget::settingsForm in Name Field 8
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form definition for the widget settings.
Overrides WidgetBase::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ NameWidget.php, line 180
Class
- NameWidget
- Plugin implementation of the 'name' widget.
Namespace
Drupal\name\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$settings = $this
->getSettings();
$element['override_field_settings'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Override shared field settings'),
'#default_value' => $this
->getSetting('override_field_settings'),
'#table_group' => 'above',
'#weight' => -100,
];
$element += $this
->getDefaultNameFormDisplaySettingsForm($settings, $form, $form_state);
// Remove inaccessible name components as defined in the field settings.
$field_settings = $this
->getFieldSettings();
$components = array_keys(array_filter($field_settings['components']));
$components = array_combine($components, $components);
$element['#excluded_components'] = array_diff_key(_name_translations(), $components);
$element['#pre_render'][] = [
$this,
'fieldSettingsFormPreRender',
];
$element['widget_layout']['#states'] = [
'visible' => [
':input[name$="[override_field_settings]"]' => [
'checked' => TRUE,
],
],
];
$element['name_settings']['#states'] = $element['widget_layout']['#states'];
return $element;
}