function Settings::getSettingsForm

Same name and namespace in other branches
  1. main core/themes/admin/src/Settings.php \Drupal\admin\Settings::getSettingsForm()

Build the settings form for the theme.

Parameters

\Drupal\Core\Session\AccountInterface|null $account: The account object.

Return value

array The theme setting form elements.

File

core/themes/admin/src/Settings.php, line 225

Class

Settings
Service to handle overridden user settings.

Namespace

Drupal\admin

Code

public function getSettingsForm(?AccountInterface $account = NULL) : array {
  $experimental_label = ' <span class="gin-experimental-flag">Experimental</span>';
  $beta_label = ' <span class="gin-beta-flag">Beta</span>';
  $form['enable_dark_mode'] = [
    '#type' => 'radios',
    '#title' => $this->t('Appearance'),
    '#description' => $this->t('Enables dark mode for the administration interface.'),
    '#default_value' => (string) ($account ? $this->get('enable_dark_mode', $account) : $this->getDefault('enable_dark_mode')),
    '#options' => [
      0 => $this->t('Light'),
      1 => $this->t('Dark'),
      'auto' => $this->t('Auto'),
    ],
  ];
  // Accent color setting.
  $presets = Helper::accentColors();
  $options = array_map(static function ($preset) {
    return $preset['label'];
  }, $presets);
  $form['preset_accent_color'] = [
    '#type' => 'radios',
    '#title' => $this->t('Accent color'),
    '#default_value' => $account ? $this->get('preset_accent_color', $account) : $this->getDefault('preset_accent_color'),
    '#options' => $options,
    '#after_build' => [
      [
        Helper::class,
        'accentRadios',
      ],
    ],
  ];
  // Accent color group.
  $form['accent_group'] = [
    '#type' => 'fieldset',
    '#title' => $this->t('Custom Accent color'),
    '#description' => $this->t('Use with caution, values should meet a11y criteria.'),
    '#states' => [
      // Show if met.
'visible' => [
        ':input[name="preset_accent_color"]' => [
          'value' => 'custom',
        ],
      ],
    ],
  ];
  // Main Accent color setting.
  $form['accent_color'] = [
    '#type' => 'textfield',
    '#placeholder' => '#777777',
    '#maxlength' => 7,
    '#size' => 7,
    '#title' => $this->t('Custom Accent color'),
    '#title_display' => 'invisible',
    '#default_value' => $account ? $this->get('accent_color', $account) : $this->getDefault('accent_color'),
    '#group' => 'accent_group',
    '#attributes' => [
      'pattern' => '^#[a-fA-F0-9]{6}',
    ],
  ];
  // Accent color picker (helper field).
  $form['accent_group']['accent_picker'] = [
    '#type' => 'color',
    '#placeholder' => '#777777',
    '#default_value' => $account ? $this->get('accent_color', $account) : $this->getDefault('accent_color'),
    '#process' => [
      [
        __CLASS__,
        'processColorPicker',
      ],
    ],
  ];
  // Focus color setting.
  $form['preset_focus_color'] = [
    '#type' => 'select',
    '#title' => $this->t('Focus color'),
    '#default_value' => $account ? $this->get('preset_focus_color', $account) : $this->getDefault('preset_focus_color'),
    '#options' => [
      'gin' => $this->t('Admin Focus color (Default)'),
      'green' => $this->t('Green'),
      'claro' => $this->t('Claro Green'),
      'orange' => $this->t('Orange'),
      'dark' => $this->t('Neutral'),
      'accent' => $this->t('Same as Accent color'),
      'custom' => $this->t('Custom'),
    ],
  ];
  // Focus color group.
  $form['focus_group'] = [
    '#type' => 'fieldset',
    '#title' => $this->t('Custom Focus color') . $beta_label,
    '#description' => $this->t('Use with caution, values should meet a11y criteria.'),
    '#states' => [
      // Show if met.
'visible' => [
        ':input[name="preset_focus_color"]' => [
          'value' => 'custom',
        ],
      ],
    ],
  ];
  // Focus color picker (helper).
  $form['focus_group']['focus_picker'] = [
    '#type' => 'color',
    '#placeholder' => '#777777',
    '#default_value' => $account ? $this->get('focus_color', $account) : $this->getDefault('focus_color'),
    '#process' => [
      [
        __CLASS__,
        'processColorPicker',
      ],
    ],
  ];
  // Custom Focus color setting.
  $form['focus_color'] = [
    '#type' => 'textfield',
    '#title' => $this->t('Custom Focus color') . $beta_label,
    '#title_display' => 'invisible',
    '#placeholder' => '#777777',
    '#maxlength' => 7,
    '#size' => 7,
    '#default_value' => $account ? $this->get('focus_color', $account) : $this->getDefault('focus_color'),
    '#group' => 'focus_group',
    '#attributes' => [
      'pattern' => '^#[a-fA-F0-9]{6}',
    ],
  ];
  // High contrast mode.
  $form['high_contrast_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Increase contrast') . $experimental_label,
    '#description' => $this->t('Enables high contrast mode.'),
    '#default_value' => $account ? $this->get('high_contrast_mode', $account) : $this->getDefault('high_contrast_mode'),
  ];
  // Layout density setting.
  $form['layout_density'] = [
    '#type' => 'radios',
    '#title' => $this->t('Layout density'),
    '#description' => $this->t('Changes the layout density for tables in the admin interface.'),
    '#default_value' => (string) ($account ? $this->get('layout_density', $account) : $this->getDefault('layout_density')),
    '#options' => [
      'default' => $this->t('Default'),
      'medium' => $this->t('Compact'),
      'small' => $this->t('Narrow'),
    ],
  ];
  // Description toggle.
  $form['show_description_toggle'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Enable form description toggle'),
    '#description' => $this->t('Show a help icon to show/hide form descriptions on content forms.'),
    '#default_value' => $account ? $this->get('show_description_toggle', $account) : $this->getDefault('show_description_toggle'),
  ];
  if (!$account) {
    foreach ($form as $key => $element) {
      $form[$key]['#after_build'][] = [
        __CLASS__,
        'overriddenSettingByUser',
      ];
    }
  }
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.