public function BooleanFormatter::settingsForm in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::settingsForm()
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. 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 elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ BooleanFormatter.php, line 63
Class
- BooleanFormatter
- Plugin implementation of the 'boolean' formatter.
Namespace
Drupal\Core\Field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$formats = [];
foreach ($this
->getOutputFormats() as $format_name => $format) {
if (is_array($format)) {
if ($format_name == 'default') {
$formats[$format_name] = $this
->t('Field settings (@on_label / @off_label)', [
'@on_label' => $format[0],
'@off_label' => $format[1],
]);
}
else {
$formats[$format_name] = $this
->t('@on_label / @off_label', [
'@on_label' => $format[0],
'@off_label' => $format[1],
]);
}
}
else {
$formats[$format_name] = $format;
}
}
$field_name = $this->fieldDefinition
->getName();
$form['format'] = [
'#type' => 'select',
'#title' => $this
->t('Output format'),
'#default_value' => $this
->getSetting('format'),
'#options' => $formats,
];
$form['format_custom_true'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom output for TRUE'),
'#default_value' => $this
->getSetting('format_custom_true'),
'#states' => [
'visible' => [
'select[name="fields[' . $field_name . '][settings_edit_form][settings][format]"]' => [
'value' => 'custom',
],
],
],
];
$form['format_custom_false'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom output for FALSE'),
'#default_value' => $this
->getSetting('format_custom_false'),
'#states' => [
'visible' => [
'select[name="fields[' . $field_name . '][settings_edit_form][settings][format]"]' => [
'value' => 'custom',
],
],
],
];
return $form;
}