public function Widget::settingsForm in Select (or other) 8.3
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 SelectOrOtherWidgetBase::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ Widget.php, line 35 - Contains \Drupal\select_or_other\Plugin\Field\FieldWidget\Widget.
Class
- Widget
- Plugin implementation of the 'select_or_other' widget.
Namespace
Drupal\select_or_other\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form['available_options'] = array(
'#type' => 'textarea',
'#title' => t('Available options'),
'#description' => t('A list of values that are, by default, available for selection. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and the label is what will be displayed to the user.'),
'#default_value' => $this
->getSetting('available_options'),
'#required' => TRUE,
);
$form['other'] = array(
'#type' => 'textfield',
'#title' => t('<em>Other</em> option'),
'#description' => t('Label for the option that the user will choose when they want to supply an <em>other</em> value.'),
'#default_value' => $this
->getSetting('other'),
'#required' => TRUE,
);
$form['other_title'] = array(
'#type' => 'textfield',
'#title' => t('<em>Other</em> field title'),
'#description' => t('Label for the field in which the user will supply an <em>other</em> value.'),
'#default_value' => $this
->getSetting('other_title'),
);
$form['other_unknown_defaults'] = array(
'#type' => 'select',
'#title' => t('<em>Other</em> value as default value'),
'#description' => t("If any incoming default values do not appear in <em>available options</em> (i.e. set as <em>other</em> values), what should happen?"),
'#options' => array(
'other' => t('Add the values to the other textfield'),
'append' => t('Append the values to the current list'),
'available' => t('Append the values to the available options'),
'ignore' => t('Ignore the values'),
),
'#default_value' => $this
->getSetting('other_unknown_defaults'),
'#required' => TRUE,
);
$form['other_size'] = array(
'#type' => 'number',
'#title' => t('<em>Other</em> field size'),
'#default_value' => $this
->getSetting('other_size'),
'#required' => TRUE,
);
$form['sort_options'] = array(
'#type' => 'checkbox',
'#title' => t('Sort options'),
'#description' => t("Sorts the options in the list alphabetically by value."),
'#default_value' => $this
->getSetting('sort_options'),
);
return $form;
}