From f70afa24a0c619d93598c308325fc8c3b38a16b8 Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@gmail.com> Date: Tue, 22 Oct 2013 19:23:46 +0000 Subject: [PATCH] refs #4126 added possibility to use other fields as well --- core/Plugin/Settings.php | 6 ++- .../templates/pluginSettings.twig | 45 ++++++++++++++++--- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/core/Plugin/Settings.php b/core/Plugin/Settings.php index 691224d662..fa78066de9 100644 --- a/core/Plugin/Settings.php +++ b/core/Plugin/Settings.php @@ -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'; @@ -45,7 +46,7 @@ class Settings $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, @@ -63,6 +64,7 @@ class Settings 'field' => static::FIELD_TEXT, 'displayedForCurrentUser' => Piwik::isUserHasSomeAdminAccess(), 'fieldAttributes' => array(), + 'selectOptions' => array(), 'description' => null, 'inlineHelp' => null, 'filter' => null, diff --git a/plugins/CoreAdminHome/templates/pluginSettings.twig b/plugins/CoreAdminHome/templates/pluginSettings.twig index ea98c12453..55341d18e0 100644 --- a/plugins/CoreAdminHome/templates/pluginSettings.twig +++ b/plugins/CoreAdminHome/templates/pluginSettings.twig @@ -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 }} @@ -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/> -- GitLab