Skip to content

Commit

Permalink
Draft theme settings guide. (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimisgold committed Sep 17, 2019
1 parent eb5422a commit d15c4d4
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/themes/theme_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Writing Theme Settings
---

You can provide users with theme settings, configurable parts of your theme that help users customize the theme to their projects. Examples of theme settings include configurable element colors, image asset uploads, footer content.

You create the form fields for your theme settings in `config/theme.ini`. Start with `[config]` as the heading under the `[info]` metadata. The `[config]` heading begins a list of theme settings; you do not need to include it over each individual setting.

```
[info]
name = "Theme Name"
,,,
[config]
```

Each theme setting is a form element, so you begin by labeling your setting, providing it with a unique lowercase name, and adding it to the list of elements.

```
[config]
elements.my_theme_setting.name = "my_theme_setting"
elements.my_theme_setting.options.label = "My Theme Setting"
```

Next you need to define your theme setting's form element type.

The available form element types from Zend framework are found in `vendor\zendframework\zend-form\src\Element`. In the config file, reference the element type with the path `Zend\Form\Element\[Type]`. The following example defines the theme setting as a checkbox.

```
elements.my_theme_setting.type = "Zend\Form\Element\Checkbox"
```

Available form elements created for Omeka sit in `application\src\Form\Element`. In the config file, reference the element type with the path `Omeka\Form\Element\[Type]`. The following example defines the theme setting as a select element containing resource templates accessible by the user.

```
elements.my_theme_setting.type = "Omeka\Form\Element\ResourceTemplateSelect"
```

This example demonstrates how to define value options for an element, in this case a radio input.

```
elements.my_theme_setting.type = "Zend\Form\Radio"
elements.my_theme_setting.options.value_options.first = "First Option"
elements.my_theme_setting.options.value_options.second = "Second Option"
elements.my_theme_setting.options.value_options.third = "Third Option"
```

You can also define html attributes for your setting's form element. This example defines the element's id.

```
elements.my_theme_setting.attributes.id = "my_theme_settings"
```

This is an example of a complete theme setting using a radio input.

```
elements.my_theme_setting.name = "my_theme_setting"
elements.my_theme_setting.attributes.id = "my_theme_setting"
elements.my_theme_setting.options.label = "My Theme Setting"
elements.my_theme_setting.type = "Zend\Form\Radio"
elements.my_theme_setting.options.value_options.first = "First Option"
elements.my_theme_setting.options.value_options.second = "Second Option"
elements.my_theme_setting.options.value_options.third = "Third Option"
```

0 comments on commit d15c4d4

Please sign in to comment.