Skip to content

Commit

Permalink
Merge pull request #6496 from marc1706/ticket/17151
Browse files Browse the repository at this point in the history
[ticket/17151] Adjust form macros to adhere to coding guidelines
  • Loading branch information
marc1706 committed Jul 30, 2023
2 parents 658e361 + d6e3daf commit 92d1af4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
10 changes: 6 additions & 4 deletions phpBB/phpbb/template/twig/extension/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public function input(environment $environment, array $form_data): string
try
{
return $environment->render('macros/forms/input.twig', [
'CLASS' => (string) ($form_data['class'] ?? ''),
'ID' => (string) ($form_data['id'] ?? ''),
'DATA' => $form_data['data'] ?? [],
'TYPE' => (string) $form_data['type'],
'NAME' => (string) $form_data['name'],
'SIZE' => (int) ($form_data['size'] ?? 0),
Expand All @@ -127,9 +129,7 @@ public function input(environment $environment, array $form_data): string
'MAX' => (int) ($form_data['max'] ?? 0),
'STEP' => (int) ($form_data['step'] ?? 0),
'CHECKED' => (bool) ($form_data['checked'] ?? false),
'CLASS' => (string) ($form_data['class'] ?? ''),
'VALUE' => (string) ($form_data['value']),
'DATA' => $form_data['data'] ?? [],
]);
}
catch (\Twig\Error\Error $e)
Expand Down Expand Up @@ -176,13 +176,13 @@ public function select(environment $environment, array $form_data): string
try
{
return $environment->render('macros/forms/select.twig', [
'ID' => (string) ($form_data['id'] ?? ''),
'CLASS' => (string) ($form_data['class'] ?? ''),
'ID' => (string) ($form_data['id'] ?? ''),
'DATA' => $form_data['data'] ?? [],
'NAME' => (string) $form_data['name'],
'TOGGLEABLE' => (bool) ($form_data['toggleable'] ?? false),
'OPTIONS' => $form_data['options'] ?? [],
'GROUP_ONLY' => (bool) ($form_data['group_only'] ?? false),
'DATA' => $form_data['data'] ?? [],
'SIZE' => (int) ($form_data['size'] ?? 0),
'MULTIPLE' => (bool) ($form_data['multiple'] ?? false),
]);
Expand All @@ -206,7 +206,9 @@ public function textarea(environment $environment, array $form_data): string
try
{
return $environment->render('macros/forms/textarea.twig', [
'CLASS' => (string) ($form_data['class'] ?? ''),
'ID' => (string) $form_data['id'],
'DATA' => $form_data['data'] ?? [],
'NAME' => (string) $form_data['name'],
'ROWS' => (int) $form_data['rows'],
'COLS' => (int) $form_data['cols'],
Expand Down
8 changes: 4 additions & 4 deletions phpBB/styles/all/template/macros/forms/input.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% apply replace({"\n": ' ', "\t": ''}) %}
<input
{% if CLASS %}class="{{ CLASS }}" {% endif %}
{% if ID %}id="{{ ID }}" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
type="{{ TYPE }}"
name="{{ NAME }}"
{% if SIZE %}size="{{ SIZE }}" {% endif %}
Expand All @@ -10,9 +14,5 @@
{% if STEP %}step="{{ STEP }}" {% endif %}
{% if TYPE == 'password' %}autocomplete="off" {% endif %}
{% if CHECKED %}checked="checked" {% endif %}
{% if CLASS %}class="{{ CLASS }}" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
value="{{ VALUE }}">
{% endapply %}
11 changes: 6 additions & 5 deletions phpBB/styles/all/template/macros/forms/select.twig
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{% 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 ID %}id="{{ ID }}" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
name="{{ NAME }}"
{% if TOGGLEABLE %}data-togglable-settings="true" {% endif %}

{% if MULTIPLE %}multiple="multiple" {% 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 %}>
{% endfor %}
label="{{ element.label }}">
{% endapply %}
{% for option in element.options %}
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}{% if option.disabled %} disabled="disabled" class="disabled-option"{% endif %}>{{ option.label }}</option>
Expand Down
9 changes: 5 additions & 4 deletions phpBB/styles/all/template/macros/forms/textarea.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% apply replace({"\n": ' ', '\t': ''}) %}
<textarea
{% if CLASS %}class="{{ CLASS }}" {% endif %}
id="{{ ID }}"
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
name="{{ NAME }}"
rows="{{ ROWS }}"
cols="{{ COLS }}">
{{ CONTENT }}
</textarea>
{% endapply %}
cols="{{ COLS }}">{% endapply %}{{ CONTENT }}</textarea>

0 comments on commit 92d1af4

Please sign in to comment.