Skip to content

Commit

Permalink
refs #4126 added possibility to use other fields as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Oct 22, 2013
1 parent 6feb011 commit f70afa2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
6 changes: 4 additions & 2 deletions core/Plugin/Settings.php
Expand Up @@ -22,9 +22,10 @@ class Settings
const TYPE_ARRAY = 'array';

const FIELD_TEXT = 'text';
const FIELD_TEXTBOX = 'textbox';
const FIELD_TEXTAREA = 'textarea';
const FIELD_RADIO = 'radio';
const FIELD_CHECKBOX = 'checkbox';
const FIELD_PASSWORD = 'password';
const FIELD_MULTI_SELECT = 'multiselect';
const FIELD_SINGLE_SELECT = 'select';

Expand All @@ -45,7 +46,7 @@ public function __construct($pluginName)

$this->defaultTypes = array(
static::FIELD_TEXT => static::TYPE_STRING,
static::FIELD_TEXTBOX => static::TYPE_STRING,
static::FIELD_TEXTAREA => static::TYPE_STRING,
static::FIELD_RADIO => static::TYPE_STRING,
static::FIELD_CHECKBOX => static::TYPE_BOOL,
static::FIELD_MULTI_SELECT => static::TYPE_ARRAY,
Expand All @@ -63,6 +64,7 @@ public function __construct($pluginName)
'field' => static::FIELD_TEXT,
'displayedForCurrentUser' => Piwik::isUserHasSomeAdminAccess(),
'fieldAttributes' => array(),
'selectOptions' => array(),
'description' => null,
'inlineHelp' => null,
'filter' => null,
Expand Down
45 changes: 38 additions & 7 deletions plugins/CoreAdminHome/templates/pluginSettings.twig
Expand Up @@ -19,6 +19,7 @@
<table class="adminTable" style='width:620px;' id="pluginSettings" data-pluginname="{{ plugin }}">

{% for setting in settings.getSettingsForCurrentUser %}
{% set settingValue = settings.getSettingValue(setting.name) %}
<tr>
<td style='width:400px'>
{{ setting.title }}
Expand All @@ -31,13 +32,43 @@
<td style='width:220px'>
<fieldset>
<label>
<input type="{{ setting.field }}"
name="{{ setting.name }}"
{% for attr, val in setting.fieldAttributes %}
{{ attr|e('html_attr') }}="{{ val|e('html_attr') }}"
{% endfor %}
value="{{ settings.getSettingValue(setting.name)|e('html_attr') }}"
>
{% if setting.field == 'select' or setting.field == 'multiselect' %}
<select
{% for attr, val in setting.fieldAttributes %}
{{ attr|e('html_attr') }}="{{ val|e('html_attr') }}"
{% endfor %}
name="{{ setting.name }}" {% if setting.field == 'multiselect' %}multiple{% endif %}>

{% for key, value in setting.selectOptions %}
<option value='{{ key }}'
{% if settingValue==key %} selected='selected' {% endif %}
>
{{ value }}
</option>
{% endfor %}

</select>
{% elseif setting.field == 'textarea' %}
<textarea
{% for attr, val in setting.fieldAttributes %}
{{ attr|e('html_attr') }}="{{ val|e('html_attr') }}"
{% endfor %}
name="{{ setting.name }}"
>
{{ settingValue }}
</textarea>
{% else %}

<input
{% for attr, val in setting.fieldAttributes %}
{{ attr|e('html_attr') }}="{{ val|e('html_attr') }}"
{% endfor %}
type="{{ setting.field }}"
name="{{ setting.name }}"
value="{{ settingValue|e('html_attr') }}"
>

{% endif %}

{% if setting.defaultValue %}
<br/>
Expand Down

0 comments on commit f70afa2

Please sign in to comment.