public function StyleswitcherAdmin::buildForm in Style Switcher 8.2
Same name and namespace in other branches
- 3.0.x src/Form/StyleswitcherAdmin.php \Drupal\styleswitcher\Form\StyleswitcherAdmin::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/ StyleswitcherAdmin.php, line 31
Class
- StyleswitcherAdmin
- Configure Style Switcher settings.
Namespace
Drupal\styleswitcher\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$styles = styleswitcher_custom_styles();
ksort($styles);
$header = [
$this
->t('Style'),
$this
->t('Operations'),
];
$rows = [];
foreach ($styles as $name => $style) {
$name_hyphenated = strtr($name, '_', '-');
list(, $name_value) = explode('/', $name_hyphenated);
$operations = [
'edit' => [
'title' => $this
->t('Edit'),
'url' => Url::fromRoute('styleswitcher.style_edit', [
'style' => $name_value,
]),
],
];
// Do not allow to delete the blank style.
if (isset($style['path'])) {
$operations['delete'] = [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('styleswitcher.style_delete', [
'style' => $name_value,
]),
];
}
// Build the table row.
$rows[] = [
[
'data' => [
'#theme' => 'styleswitcher_admin_style_overview',
'#style' => $style,
],
],
[
'data' => [
'#type' => 'operations',
'#links' => $operations,
],
],
];
}
$form['styleswitcher_custom_styles'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
$form['enable_overlay'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable overlay'),
'#description' => $this
->t('Enable the overlay and fade when switching stylesheets.'),
'#default_value' => $this
->config('styleswitcher.settings')
->get('enable_overlay'),
];
return parent::buildForm($form, $form_state);
}