public function PatternFormatter::settingsForm in UI Patterns Field Formatters 8
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
- src/
Plugin/ Field/ FieldFormatter/ PatternFormatter.php, line 149
Class
- PatternFormatter
- Plugin implementation of the 'pattern' formatter.
Namespace
Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$field_storage_definition = $this->fieldDefinition
->getFieldStorageDefinition();
$context = [
'storageDefinition' => $field_storage_definition,
'limit' => $field_storage_definition
->getPropertyNames(),
];
// Some modifications to make 'variant' default value working.
$configuration = $this
->getSettings();
$pattern = $this
->getSetting('pattern');
$pattern_variant = $this
->getCurrentVariant($pattern);
if (isset($pattern_variant)) {
$configuration['pattern_variant'] = $pattern_variant;
}
$this
->buildPatternDisplayForm($form, 'field_properties', $context, $configuration);
return $form;
}