public function SettingsForm::buildForm in Display Suite 8.3
Same name and namespace in other branches
- 8.4 src/Form/SettingsForm.php \Drupal\ds\Form\SettingsForm::buildForm()
- 8.2 src/Form/SettingsForm.php \Drupal\ds\Form\SettingsForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ SettingsForm.php, line 95
Class
- SettingsForm
- Configures Display Suite settings for this site.
Namespace
Drupal\ds\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('ds.settings');
$form['additional_settings'] = [
'#type' => 'vertical_tabs',
'#attached' => [
'library' => [
'ds/admin',
],
],
];
$form['fs1'] = [
'#type' => 'details',
'#title' => $this
->t('Field Templates'),
'#group' => 'additional_settings',
'#weight' => 1,
'#tree' => TRUE,
'#collapsed' => FALSE,
];
$form['fs1']['field_template'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Field Templates'),
'#description' => $this
->t('Customize the labels and the HTML output of your fields.'),
'#default_value' => $config
->get('field_template'),
];
$form['fs1']['ft-layout-builder'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable field templates in Layout Builder'),
'#description' => $this
->t('Enable field templates on Layout Builder field blocks. Note that disabling this after having configured layout builder field templates will require a cache clear.'),
'#default_value' => $config
->get('ft-layout-builder'),
'#states' => [
'visible' => [
'input[name="fs1[field_template]"]' => [
'checked' => TRUE,
],
],
],
];
$theme_functions = Ds::getFieldLayoutOptions();
$url = new Url('ds.classes');
$description = $this
->t('<br/>Default will output the field as defined in Drupal Core.<br/>' . 'Reset will strip all HTML.<br/>' . 'Minimal adds a simple wrapper around the field.<br/>' . 'There is also an Expert Field Template that gives full control over the HTML, but can only be set per field.<br/><br/>' . 'You can override this setting per field on the "Manage display" screens or when creating fields on the instance level.<br/><br/>' . '<strong>Template suggestions</strong><br/>' . 'You can create .html.twig files as well for these field theme functions, e.g. field--reset.html.twig, field--minimal.html.twig<br/><br/>' . '<label>CSS classes</label>You can add custom CSS classes on the <a href=":url">classes form</a>. These classes can be added to fields using the Default Field Template.<br/><br/>' . '<label>Advanced</label>You can create your own custom field templates plugin. See Drupal\\ds_test\\Plugin\\DsFieldTemplate for an example.', [
':url' => $url
->toString(),
]);
$form['fs1']['ft-default'] = [
'#type' => 'select',
'#title' => $this
->t('Default Field Template'),
'#options' => $theme_functions,
'#default_value' => $config
->get('ft-default'),
'#description' => $description,
'#states' => [
'visible' => [
'input[name="fs1[field_template]"]' => [
'checked' => TRUE,
],
],
],
];
$form['fs1']['ft-show-colon'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show colon'),
'#default_value' => $config
->get('ft-show-colon'),
'#description' => $this
->t('Show the colon on the reset field template.'),
'#states' => [
'visible' => [
'select[name="fs1[ft-default]"]' => [
'value' => 'reset',
],
'input[name="fs1[field_template]"]' => [
'checked' => TRUE,
],
],
],
];
$form['fs3'] = [
'#type' => 'details',
'#title' => $this
->t('Other'),
'#group' => 'additional_settings',
'#weight' => 3,
'#tree' => TRUE,
];
$form['fs3']['use_field_names'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use field names in templates'),
'#default_value' => $config
->get('use_field_names'),
'#description' => $this
->t('Use field names in twig templates instead of the key'),
];
return parent::buildForm($form, $form_state);
}