diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index a724b7296c..84254744c4 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1116,44 +1116,71 @@ class acp_board } /** - * Select default dateformat - */ - function dateformat_select($value, $key) + * Create select for default date format + * + * @param string $value Current date format value + * @param string $key Date format key + */ + public function dateformat_select(string $value, string $key): array { - global $user, $config; - // Let the format_date function operate with the acp values - $old_tz = $user->timezone; + $old_tz = $this->user->timezone; try { - $user->timezone = new DateTimeZone($config['board_timezone']); + $this->user->timezone = new DateTimeZone($this->config['board_timezone']); } catch (\Exception $e) { // If the board timezone is invalid, we just use the users timezone. } - $dateformat_options = ''; + $dateformat_options = []; - foreach ($user->lang['dateformats'] as $format => $null) + $dateformats = $this->language->lang_raw('dateformats'); + if (!is_array($dateformats)) { - $dateformat_options .= ''; + $dateformats = []; } - $dateformat_options .= ''; + + // Add custom entry + $dateformat_options[] = [ + 'value' => 'custom', + 'selected' => !isset($dateformats[$value]), + 'label' => $this->language->lang('CUSTOM_DATEFORMAT'), + ]; // Reset users date options - $user->timezone = $old_tz; + $this->user->timezone = $old_tz; - return " - "; + return [ + [ + 'tag' => 'select', + 'name' => 'dateoptions', + 'id' => 'dateoptions', + 'options' => $dateformat_options, + 'data' => [ + 'dateoption' => $key, + 'dateoption-default' => $value, + ] + ], + [ + 'tag' => 'input', + 'type' => 'text', + 'name' => "config[$key]", + 'id' => $key, + 'value' => $value, + 'maxlength' => 64, + ] + ]; } /** diff --git a/phpBB/phpbb/template/twig/extension/forms.php b/phpBB/phpbb/template/twig/extension/forms.php index 8715ce585e..06d5d21328 100644 --- a/phpBB/phpbb/template/twig/extension/forms.php +++ b/phpBB/phpbb/template/twig/extension/forms.php @@ -129,6 +129,7 @@ class forms extends AbstractExtension '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) @@ -181,6 +182,8 @@ class forms extends AbstractExtension '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), ]); } catch (\Twig\Error\Error $e) diff --git a/phpBB/styles/all/template/macros/forms/input.twig b/phpBB/styles/all/template/macros/forms/input.twig index cf58826235..c902552ce7 100644 --- a/phpBB/styles/all/template/macros/forms/input.twig +++ b/phpBB/styles/all/template/macros/forms/input.twig @@ -11,5 +11,8 @@ {% 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 %} diff --git a/phpBB/styles/all/template/macros/forms/select.twig b/phpBB/styles/all/template/macros/forms/select.twig index 2f16a1afe2..45c84a42ca 100644 --- a/phpBB/styles/all/template/macros/forms/select.twig +++ b/phpBB/styles/all/template/macros/forms/select.twig @@ -4,6 +4,9 @@ {% if CLASS %}class="{{ CLASS }}" {% endif %} name="{{ NAME }}" {% if TOGGLEABLE %}data-togglable-settings="true" {% endif %} + {% for attribute, attribute_value in DATA %} + data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}" + {% endfor %} {% if SIZE %}size="{{ SIZE }}" {% endif %}> {% endapply %} {% for element in OPTIONS %}