public function ColorFieldFormatterCss::settingsForm in Color Field 8.2
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/ ColorFieldFormatterCss.php, line 94
Class
- ColorFieldFormatterCss
- Plugin implementation of the color_field css declaration formatter.
Namespace
Drupal\color_field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = [];
$elements['selector'] = [
'#title' => $this
->t('Selector'),
'#description' => $this
->t('A valid CSS selector such as <code>.links > li > a, #logo</code>. You can use tokens as shown below.'),
'#type' => 'textarea',
'#rows' => '1',
'#default_value' => $this
->getSetting('selector'),
'#required' => TRUE,
'#placeholder' => 'body > div > a',
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][advanced]"]' => [
'checked' => FALSE,
],
],
],
];
$elements['property'] = [
'#title' => $this
->t('Property'),
'#type' => 'select',
'#default_value' => $this
->getSetting('property'),
'#required' => TRUE,
'#options' => [
'background-color' => $this
->t('Background color'),
'color' => $this
->t('Text color'),
],
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][advanced]"]' => [
'checked' => FALSE,
],
],
],
];
$elements['important'] = [
'#title' => $this
->t('Important'),
'#description' => $this
->t('Whenever this declaration is more important than others.'),
'#type' => 'checkbox',
'#default_value' => $this
->getSetting('important'),
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][advanced]"]' => [
'checked' => FALSE,
],
],
],
];
if ($this
->getFieldSetting('opacity')) {
$elements['opacity'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display opacity'),
'#default_value' => $this
->getSetting('opacity'),
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][advanced]"]' => [
'checked' => FALSE,
],
],
],
];
}
$elements['advanced'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Advanced Mode'),
'#default_value' => $this
->getSetting('advanced'),
'#description' => t('Switch to advanced mode and build the css yourself.'),
];
$elements['css'] = [
'#type' => 'textarea',
'#title' => $this
->t('CSS'),
'#default_value' => $this
->getSetting('css'),
'#description' => t('Create the css statement yourself. This lets you for example, control multiple element aspects at once. You can use tokens as shown below.'),
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][advanced]"]' => [
'checked' => TRUE,
],
],
],
'#element_validate' => [
'token_element_validate',
],
'#token_types' => [
$this->fieldDefinition
->getTargetEntityTypeId(),
'color_field',
],
];
$elements['token_help'] = [
'#theme' => 'token_tree_link',
'#token_types' => [
$this->fieldDefinition
->getTargetEntityTypeId(),
'color_field',
],
];
return $elements;
}