mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-13 20:24:08 +02:00
[ticket/17100] Use twig functions for form elements
PHPBB3-17100
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
{% macro input(form_data) %}
|
||||
{% apply replace({"\n": ' ', '\t': ''}) %}
|
||||
<input
|
||||
{% if form_data.id %}id="{{ form_data.id }}"{% endif %}
|
||||
type="{{ form_data.type }}"
|
||||
name="{{ form_data.name }}"
|
||||
{% if form_data.size %}size="{{ form_data.size }}"{% endif %}
|
||||
{% if form_data.maxlength %}maxlength="{{ form_data.maxlength }}"{% endif %}
|
||||
{% if form_data.min %}min="{{ form_data.min }}"{% endif %}
|
||||
{% if form_data.max %}max="{{ form_data.max }}"{% endif %}
|
||||
{% if form_data.step %}step="{{ form_data.step }}"{% endif %}
|
||||
{% if form_data.type == 'password' %}autocomplete="off"{% endif %}
|
||||
{% if form_data.checked %}checked="checked"{% endif %}
|
||||
{% if form_data.class %}class="{{ form_data.class }}"{% endif %}
|
||||
value="{{ form_data.value }}">
|
||||
{% endapply %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro dimension(form_data) %}
|
||||
{{ _self.input(form_data.width) }} x {{ _self.input(form_data.height) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro textarea(form_data) %}
|
||||
{% apply replace({"\n": ' ', '\t': ''}) %}
|
||||
<textarea
|
||||
id="{{ form_data.id }}"
|
||||
name="{{ form_data.name }}"
|
||||
rows="{{ form_data.rows }}"
|
||||
cols="{{ form_data.cols }}">
|
||||
{{ form_data.content }}
|
||||
</textarea>
|
||||
{% endapply %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro radio_buttons(form_data) %}
|
||||
<label>{{ _self.input(form_data.buttons[0]) ~ form_data.buttons[0].label }}</label>
|
||||
<label>{{ _self.input(form_data.buttons[1]) ~ form_data.buttons[1].label }}</label>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro select(form_data, class, id, name, group_only) %}
|
||||
{% apply replace({"\n": ' ', '\t': ''}) %}
|
||||
<select
|
||||
{% if id %}id="{{ id }}"{% endif %}
|
||||
{% if class %}class="{{ class }}"{% endif %}
|
||||
name="{% if name %}{{ name }}{% else %}{{ form_data.name }}{% endif %}"
|
||||
{% if form_data.toggleable %}data-togglable-settings="true"{% endif %}
|
||||
{% if form_data.size %}size="{{ form_data.size }}"{% endif %}>
|
||||
{% endapply %}
|
||||
{% for element in form_data.options %}
|
||||
{% if not group_only and element.options %}
|
||||
{% apply replace({"\n": ' ', '\t': ''}) %}
|
||||
<optgroup
|
||||
label="{{ element.label }}"
|
||||
{% for key, value in element.data %}
|
||||
data-{{ key }}="{{ value }}"
|
||||
{% endfor %}>
|
||||
{% endapply %}
|
||||
{% for option in element.options %}
|
||||
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}>{{ option.label }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% else %}
|
||||
<option value="{{ element.value }}"{% if element.selected %} selected="selected"{% endif %}>{{ element.label }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro build_template(form_data) %}
|
||||
{% if form_data.tag == 'input' %}
|
||||
{{ _self.input(form_data) }}
|
||||
{% elseif form_data.tag == 'dimension' %}
|
||||
{{ _self.dimension(form_data) }}
|
||||
{% elseif form_data.tag == 'radio' %}
|
||||
{{ _self.radio_buttons(form_data) }}
|
||||
{% elseif form_data.tag == 'select' %}
|
||||
{{ _self.select(form_data) }}
|
||||
{% elseif form_data.tag == 'textarea' %}
|
||||
{{ _self.textarea(form_data) }}
|
||||
{% elseif form_data[0] %}
|
||||
{% for element in form_data %}
|
||||
{{ _self.build_template(element) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if form_data.append %}{{ form_data.append }}{% endif %}
|
||||
{% endmacro %}
|
16
phpBB/styles/all/template/macros/forms/build_template.twig
Normal file
16
phpBB/styles/all/template/macros/forms/build_template.twig
Normal file
@@ -0,0 +1,16 @@
|
||||
{% if form_data.tag == 'input' %}
|
||||
{{ FormsInput(form_data) }}
|
||||
{% elseif form_data.tag == 'dimension' %}
|
||||
{{ FormsDimension(form_data) }}
|
||||
{% elseif form_data.tag == 'radio' %}
|
||||
{{ FormsRadioButtons(form_data) }}
|
||||
{% elseif form_data.tag == 'select' %}
|
||||
{{ FormsSelect(form_data) }}
|
||||
{% elseif form_data.tag == 'textarea' %}
|
||||
{{ FormsTextarea(form_data) }}
|
||||
{% elseif form_data[0] %}
|
||||
{% for element in form_data %}
|
||||
{{ FormsBuildTemplate(element) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if form_data.append %}{{ form_data.append }}{% endif %}
|
1
phpBB/styles/all/template/macros/forms/dimension.twig
Normal file
1
phpBB/styles/all/template/macros/forms/dimension.twig
Normal file
@@ -0,0 +1 @@
|
||||
{{ FormsInput(WIDTH) }} x {{ FormsInput(HEIGHT) }}
|
15
phpBB/styles/all/template/macros/forms/input.twig
Normal file
15
phpBB/styles/all/template/macros/forms/input.twig
Normal file
@@ -0,0 +1,15 @@
|
||||
{% apply replace({"\n": ' ', "\t": ''}) %}
|
||||
<input
|
||||
{% if ID %}id="{{ ID }}" {% endif %}
|
||||
type="{{ TYPE }}"
|
||||
name="{{ NAME }}"
|
||||
{% if SIZE %}size="{{ SIZE }}" {% endif %}
|
||||
{% if MAXLENGTH %}maxlength="{{ MAXLENGTH }}" {% endif %}
|
||||
{% if MIN %}min="{{ MIN }}" {% endif %}
|
||||
{% if MAX %}max="{{ MAX }}" {% endif %}
|
||||
{% if STEP %}step="{{ STEP }}" {% endif %}
|
||||
{% if TYPE == 'password' %}autocomplete="off" {% endif %}
|
||||
{% if CHECKED %}checked="checked" {% endif %}
|
||||
{% if CLASS %}class="{{ CLASS }}" {% endif %}
|
||||
value="{{ VALUE }}">
|
||||
{% endapply %}
|
@@ -0,0 +1,2 @@
|
||||
<label>{{ FormsInput(FIRST_BUTTON) ~ FIRST_BUTTON_LABEL }}</label>
|
||||
<label>{{ FormsInput(SECOND_BUTTON) ~ SECOND_BUTTON_LABEL }}</label>
|
26
phpBB/styles/all/template/macros/forms/select.twig
Normal file
26
phpBB/styles/all/template/macros/forms/select.twig
Normal file
@@ -0,0 +1,26 @@
|
||||
{% apply replace({"\n": ' ', "\t": ''}) %}
|
||||
<select
|
||||
{% if ID %}id="{{ ID }}" {% endif %}
|
||||
{% if CLASS %}class="{{ CLASS }}" {% endif %}
|
||||
name="{{ NAME }}"
|
||||
{% if TOGGLEABLE %}data-togglable-settings="true" {% endif %}
|
||||
{% if SIZE %}size="{{ SIZE }}" {% endif %}>
|
||||
{% endapply %}
|
||||
{% for element in OPTIONS %}
|
||||
{% if not GROUP_ONLY and element.options %}
|
||||
{% apply replace({"\n": ' ', '\t': ''}) %}
|
||||
<optgroup
|
||||
label="{{ element.label }}"
|
||||
{% for key, value in element.data %}
|
||||
data-{{ key }}="{{ value }}"
|
||||
{% endfor %}>
|
||||
{% endapply %}
|
||||
{% for option in element.options %}
|
||||
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}>{{ option.label }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% else %}
|
||||
<option value="{{ element.value }}"{% if element.selected %} selected="selected"{% endif %}>{{ element.label }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
9
phpBB/styles/all/template/macros/forms/textarea.twig
Normal file
9
phpBB/styles/all/template/macros/forms/textarea.twig
Normal file
@@ -0,0 +1,9 @@
|
||||
{% apply replace({"\n": ' ', '\t': ''}) %}
|
||||
<textarea
|
||||
id="{{ ID }}"
|
||||
name="{{ NAME }}"
|
||||
rows="{{ ROWS }}"
|
||||
cols="{{ COLS }}">
|
||||
{{ CONTENT }}
|
||||
</textarea>
|
||||
{% endapply %}
|
@@ -1,16 +1,15 @@
|
||||
<dl>
|
||||
{% from "macros/form_macros.twig" import select %}
|
||||
<dt><label for="timezone">{{ lang('BOARD_TIMEZONE') ~ lang('COLON') }}</label></dt>
|
||||
{% if TIMEZONE_OPTIONS %}
|
||||
<dd id="tz_select_date hidden">
|
||||
{% set tz_date_data = TIMEZONE_OPTIONS|merge({ options: [{ value: "", label: lang('SELECT_CURRENT_TIME') }]|merge(TIMEZONE_OPTIONS.options) }) %}
|
||||
{{ select(tz_date_data, 'autowidth tz_select', 'tz_date', 'tz_date', true) }}
|
||||
{% set tz_date_data = TIMEZONE_OPTIONS | merge({ options: [{ value: "", label: lang('SELECT_CURRENT_TIME') }] | merge(TIMEZONE_OPTIONS.options) }) %}
|
||||
{{ FormsSelect(tz_date_data | merge({class: 'autowidth tz_select', id: 'tz_date', name: 'tz_date', group_only: true})) }}
|
||||
<input type="button" id="tz_select_date_suggest" class="button1 button button-form-bold" style="display: none;" timezone-preselect="<!-- IF S_TZ_PRESELECT -->true<!-- ELSE -->false<!-- ENDIF -->" data-l-suggestion="{L_TIMEZONE_DATE_SUGGESTION}" value="{L_TIMEZONE_DATE_SUGGESTION}" />
|
||||
</dd>
|
||||
{% endif %}
|
||||
<dd>
|
||||
{% set tz_select_data = TIMEZONE_OPTIONS|merge({ options: [{ value: "", label: lang('SELECT_TIMEZONE') }]|merge(TIMEZONE_OPTIONS.options) }) %}
|
||||
{{ select(tz_select_data, 'autowidth tz_select timezone', 'timezone') }}
|
||||
{% set tz_select_data = TIMEZONE_OPTIONS | merge({ options: [{ value: "", label: lang('SELECT_TIMEZONE') }] | merge(TIMEZONE_OPTIONS.options) }) %}
|
||||
{{ FormsSelect(tz_select_data | merge({class: 'autowidth tz_select', id: 'timezone'})) }}
|
||||
|
||||
{% INCLUDEJS('timezone.js') %}
|
||||
</dd>
|
||||
|
@@ -6,8 +6,7 @@
|
||||
<form method="post" action="{S_UCP_ACTION}" id="register">
|
||||
<p class="rightside">
|
||||
<label for="{{ LANG_OPTIONS.id }}">{{ lang('LANGUAGE') ~ lang('COLON') }}</label>
|
||||
{% import "macros/form_macros.twig" as form_macros %}
|
||||
{{ form_macros.select(LANG_OPTIONS) }}
|
||||
{{ FormsSelect(LANG_OPTIONS) }}
|
||||
{S_HIDDEN_FIELDS}
|
||||
</p>
|
||||
</form>
|
||||
|
@@ -54,8 +54,7 @@
|
||||
<dl>
|
||||
<dt><label for="{{ LANG_OPTIONS.id }}">{L_BOARD_LANGUAGE}{L_COLON}</label></dt>
|
||||
<dd>
|
||||
{% import "macros/form_macros.twig" as form_macros %}
|
||||
{{ form_macros.select(LANG_OPTIONS) }}
|
||||
{{ FormsSelect(LANG_OPTIONS) }}
|
||||
</dd>
|
||||
</dl>
|
||||
<!-- ENDIF -->
|
||||
|
@@ -61,8 +61,7 @@
|
||||
<dl>
|
||||
<dt><label for="{{ LANG_OPTIONS.id }}">{{ lang('LANGUAGE') ~ lang('COLON') }}</label></dt>
|
||||
<dd>
|
||||
{% import "macros/form_macros.twig" as form_macros %}
|
||||
{{ form_macros.select(LANG_OPTIONS) }}
|
||||
{{ FormsSelect(LANG_OPTIONS) }}
|
||||
</dd>
|
||||
</dl>
|
||||
<script>
|
||||
|
Reference in New Issue
Block a user