Skip to content

Commit

Permalink
Port columns_definitions/column_default to Twig
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Oct 18, 2017
1 parent 536caac commit efacd3e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 57 deletions.
15 changes: 9 additions & 6 deletions libraries/classes/CentralColumns.php
Expand Up @@ -931,11 +931,12 @@ public static function getHtmlForCentralColumnsTableRow(array $row, $row_num, $d
. Template::get('columns_definitions/column_default')
->render(
array(
'columnNumber' => $row_num,
'column_number' => $row_num,
'ci' => 3,
'ci_offset' => 0,
'type_upper' => mb_strtoupper($row['col_type']),
'columnMeta' => $meta
'column_meta' => $meta,
'char_editing' => $GLOBALS['cfg']['CharEditing'],
)
)
. '</td>';
Expand Down Expand Up @@ -1072,11 +1073,12 @@ public static function getHtmlForCentralColumnsEditTableRow(array $row, $row_num
. Template::get('columns_definitions/column_default')
->render(
array(
'columnNumber' => $row_num,
'column_number' => $row_num,
'ci' => 3,
'ci_offset' => 0,
'type_upper' => mb_strtoupper($row['col_default']),
'columnMeta' => $meta
'column_meta' => $meta,
'char_editing' => $GLOBALS['cfg']['CharEditing'],
)
)
. '</td>';
Expand Down Expand Up @@ -1321,11 +1323,12 @@ public static function getHtmlForAddNewColumn($db, $total_rows)
. Template::get('columns_definitions/column_default')
->render(
array(
'columnNumber' => 0,
'column_number' => 0,
'ci' => 3,
'ci_offset' => 0,
'type_upper' => '',
'columnMeta' => array()
'column_meta' => array(),
'char_editing' => $GLOBALS['cfg']['CharEditing'],
)
)
. '</td>'
Expand Down
1 change: 1 addition & 0 deletions libraries/classes/Twig/PhpFunctionsExtension.php
Expand Up @@ -26,6 +26,7 @@ public function getFunctions()
{
return array(
new Twig_SimpleFunction('array_search', 'array_search'),
new Twig_SimpleFunction('bin2hex', 'bin2hex'),
new Twig_SimpleFunction('md5', 'md5'),
new Twig_SimpleFunction('preg_replace', 'preg_replace'),
new Twig_SimpleFunction('strpos', 'strpos'),
Expand Down
5 changes: 3 additions & 2 deletions templates/columns_definitions/column_attributes.phtml
Expand Up @@ -45,11 +45,12 @@ $ci_offset = -1;
<!-- column default -->
<?= PhpMyAdmin\Template::get('columns_definitions/column_default')
->render(array(
'columnNumber' => $columnNumber,
'column_number' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'type_upper' => isset($type_upper) ? $type_upper : null,
'columnMeta' => isset($columnMeta) ? $columnMeta : null
'column_meta' => isset($columnMeta) ? $columnMeta : null,
'char_editing' => $GLOBALS['cfg']['CharEditing'],
)); ?>
</td>
<td class="center">
Expand Down
49 changes: 0 additions & 49 deletions templates/columns_definitions/column_default.phtml

This file was deleted.

46 changes: 46 additions & 0 deletions templates/columns_definitions/column_default.twig
@@ -0,0 +1,46 @@
{# here we put 'NONE' as the default value of drop-down; otherwise users would
have problems if they forget to enter the default value (example, for an INT) #}
{% set translation %}{% trans %}None{% context %}for default{% endtrans %}{% endset %}
{% set default_options = {
'NONE': translation,
'USER_DEFINED': 'As defined:'|trans,
'NULL': 'NULL',
'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP'
} %}

{# For a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value #}
{% set default_value = '' %}
{% if column_meta['DefaultValue'] is defined %}
{% set default_value = column_meta['DefaultValue'] %}
{% endif %}
{% if type_upper == 'BIT' %}
{% set default_value = Util_convertBitDefaultValue(column_meta['DefaultValue']) %}
{% elseif type_upper == 'BINARY' or type_upper == 'VARBINARY' %}
{% set default_value = bin2hex(column_meta['DefaultValue']) %}
{% endif %}

<select name="field_default_type[{{ column_number }}]"
id="field_{{ column_number }}_{{ ci - ci_offset }}"
class="default_type">
{% for key, value in default_options %}
<option value="{{ key }}"
{%- if column_meta['DefaultType'] is defined
and column_meta['DefaultType'] == key %}
selected="selected"
{%- endif %}>
{{ value }}
</option>
{% endfor %}
</select>
{% if char_editing == 'textarea' %}
<textarea name="field_default_value[{{ column_number }}]"
cols="15"
class="textfield
default_value">{{ default_value }}</textarea>
{% else %}
<input type="text"
name="field_default_value[{{ column_number }}]"
size="12"
value="{{ default_value }}"
class="textfield default_value" />
{% endif %}

0 comments on commit efacd3e

Please sign in to comment.