[ticket/15699] Update acp_storage to work with form macros

PHPBB3-15699
This commit is contained in:
Ruben Calvo 2024-05-25 04:53:09 +02:00
parent 155b5168be
commit de73a2e3d7
No known key found for this signature in database
2 changed files with 56 additions and 13 deletions

View file

@ -74,10 +74,30 @@
{% set input_name = storage.get_name ~ '[' ~ name ~ ']' %}
{% set input_value = attribute(config, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name) %}
{% if options['type'] in ['text', 'password', 'email'] %}
{{ FormsBuildTemplate(options | merge({"name": input_name, "value": input_value})) }}
{% elseif options['type'] == 'textarea' %}
{{ FormsBuildTemplate(options | merge({"name": input_name, "content": input_value})) }}
{% if options.tag == 'input' %}
{{ FormsInput(options | merge({"name": input_name, "value": input_value})) }}
{% elseif options.tag == 'textarea' %}
{{ FormsTextarea(options | merge({"name": input_name, "content": input_value})) }}
{% elseif options.tag == 'radio' %}
{% set buttons = [] %}
{% for button in options.buttons %}
{% set checked = button.value == input_value %}
{% set new_button = button | merge({"name": input_name, "checked": checked}) %}
{% set buttons = buttons | merge([new_button]) %}
{% endfor %}
{{ FormsRadioButtons(options | merge({"buttons": buttons})) }}
{% elseif options.tag == 'select' %}
{% set select_options = [] %}
{% for option in options.options %}
{% set selected = option.value == input_value %}
{% set new_option = option | merge({"selected": selected}) %}
{% set select_options = select_options | merge([new_option]) %}
{% endfor %}
{{ FormsSelect(options | merge({"name": input_name, "options": select_options})) }}
{% endif %}
</dd>
</dl>

View file

@ -458,7 +458,7 @@ class acp_storage
$this->db->sql_freeresult($result);
$total_count = $done_count + $remain_count;
$percent = $done_count / $total_count;
$percent = $total_count > 0 ? $done_count / $total_count : 0;
$steps = $this->state_helper->storage_index() + $this->state_helper->remove_storage_index() + $percent;
$multiplier = $this->state_helper->update_type() === update_type::MOVE ? 2 : 1;
@ -509,18 +509,15 @@ class acp_storage
$value = $this->request->variable([$storage_name, $definition_key], '');
switch ($definition_value['type'])
switch ($definition_value['tag'])
{
case 'email':
if (!filter_var($value, FILTER_VALIDATE_EMAIL))
case 'text':
if ($definition_value['type'] == 'email' && filter_var($value, FILTER_VALIDATE_EMAIL))
{
$messages[] = $this->lang->lang('STORAGE_FORM_TYPE_EMAIL_INCORRECT_FORMAT', $definition_title, $storage_title);
}
// no break
case 'text':
case 'password':
$maxlength = isset($definition_value['maxlength']) ? $definition_value['maxlength'] : 255;
$maxlength = isset($definition_value['max']) ? $definition_value['max'] : 255;
if (strlen($value) > $maxlength)
{
$messages[] = $this->lang->lang('STORAGE_FORM_TYPE_TEXT_TOO_LONG', $definition_title, $storage_title);
@ -542,8 +539,34 @@ class acp_storage
break;
case 'radio':
$found = false;
foreach ($definition_value['buttons'] as $button)
{
if ($button['value'] == $value)
{
$found = true;
break;
}
}
if (!$found)
{
$messages[] = $this->lang->lang('STORAGE_FORM_TYPE_SELECT_NOT_AVAILABLE', $definition_title, $storage_title);
}
break;
case 'select':
if (!in_array($value, array_values($definition_value['options'])))
$found = false;
foreach ($definition_value['options'] as $option)
{
if ($option['value'] == $value)
{
$found = true;
break;
}
}
if (!$found)
{
$messages[] = $this->lang->lang('STORAGE_FORM_TYPE_SELECT_NOT_AVAILABLE', $definition_title, $storage_title);
}