Visitar URL original
Remove templates/server/select/server_options.twig · phpmyadmin/phpmyadmin@f243cf5 · GitHub
Skip to content

Commit f243cf5

Browse files
committed
Remove templates/server/select/server_options.twig
Merges it with the templates/server/select/index.twig template. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 41847a8 commit f243cf5

3 files changed

Lines changed: 26 additions & 54 deletions

File tree

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
/**
3-
* Code for displaying server selection
4-
*/
52

63
declare(strict_types=1);
74

@@ -24,35 +21,32 @@ class Select
2421
/**
2522
* Renders the server selection in list or selectbox form, or option tags only
2623
*
27-
* @param bool $not_only_options whether to include form tags or not
28-
* @param bool $omit_fieldset whether to omit fieldset tag or not
24+
* @param bool $notOnlyOptions whether to include form tags or not
25+
* @param bool $omitFieldset whether to omit fieldset tag or not
2926
*/
30-
public static function render(bool $not_only_options, bool $omit_fieldset): string
27+
public static function render(bool $notOnlyOptions, bool $omitFieldset): string
3128
{
3229
// Show as list?
33-
if ($not_only_options) {
30+
if ($notOnlyOptions) {
3431
$list = $GLOBALS['cfg']['DisplayServersList'];
35-
$not_only_options = ! $list;
32+
$notOnlyOptions = ! $list;
3633
} else {
3734
$list = false;
3835
}
3936

40-
$form_action = '';
41-
if ($not_only_options) {
42-
$form_action = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server');
37+
$formAction = '';
38+
if ($notOnlyOptions) {
39+
$formAction = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server');
4340
}
4441

45-
$servers = [];
42+
/** @var array{list: list<array<string, mixed>>, select: list<array<string, mixed>>} $servers */
43+
$servers = ['list' => [], 'select' => []];
4644
foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
4745
if (empty($server['host'])) {
4846
continue;
4947
}
5048

51-
if (! empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
52-
$selected = 1;
53-
} else {
54-
$selected = 0;
55-
}
49+
$selected = ! empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key;
5650

5751
if (! empty($server['verbose'])) {
5852
$label = $server['verbose'];
@@ -78,41 +72,27 @@ public static function render(bool $not_only_options, bool $omit_fieldset): stri
7872

7973
if ($list) {
8074
if ($selected) {
81-
$servers['list'][] = [
82-
'selected' => true,
83-
'label' => $label,
84-
];
75+
$servers['list'][] = ['selected' => true, 'href' => '', 'label' => $label];
8576
} else {
8677
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server');
8778
$href = $scriptName . Url::getCommon(
8879
['server' => $key],
8980
! str_contains($scriptName, '?') ? '?' : '&',
9081
);
91-
$servers['list'][] = [
92-
'href' => $href,
93-
'label' => $label,
94-
];
82+
$servers['list'][] = ['selected' => false, 'href' => $href, 'label' => $label];
9583
}
9684
} else {
97-
$servers['select'][] = [
98-
'value' => $key,
99-
'selected' => $selected,
100-
'label' => $label,
101-
];
85+
$servers['select'][] = ['value' => $key, 'selected' => $selected, 'label' => $label];
10286
}
10387
}
10488

105-
$renderDetails = [
106-
'not_only_options' => $not_only_options,
107-
'omit_fieldset' => $omit_fieldset,
108-
'servers' => $servers,
109-
];
110-
if ($not_only_options) {
111-
$renderDetails['form_action'] = $form_action;
112-
}
113-
11489
$template = new Template();
11590

116-
return $template->render('server/select/index', $renderDetails);
91+
return $template->render('server/select/index', [
92+
'not_only_options' => $notOnlyOptions,
93+
'omit_fieldset' => $omitFieldset,
94+
'servers' => $servers,
95+
'form_action' => $formAction,
96+
]);
11797
}
11898
}

‎templates/server/select/index.twig‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<label for="select_server">{% trans 'Current server:' %}</label>
88
<select id="select_server" class="autosubmit" name="server">
99
<option value="">({% trans 'Servers' %}) ...</option>
10-
{% include 'server/select/server_options.twig' with {
11-
'select': servers.select
12-
} only %}
10+
{% for server in servers.select %}
11+
<option value="{{ server.value }}"{{ server.selected ? ' selected' }}>{{ server.label }}</option>
12+
{% endfor %}
1313
</select>
1414
{% if omit_fieldset == false %}
1515
</fieldset>
@@ -31,7 +31,7 @@
3131
</li>
3232
</ul>
3333
{% else %}
34-
{% include 'server/select/server_options.twig' with {
35-
'select': servers.select
36-
} only %}
34+
{% for server in servers.select %}
35+
<option value="{{ server.value }}"{{ server.selected ? ' selected' }}>{{ server.label }}</option>
36+
{% endfor %}
3737
{% endif %}

‎templates/server/select/server_options.twig‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)