Skip to content

Commit

Permalink
Fix up index/view for enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 28, 2023
1 parent c4f2ab2 commit 1df72e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/View/Helper/BakeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ public function getViewFieldsData(array $fields, SchemaInterface $schema, array
if (isset($associationFields[$field])) {
return 'string';
}
if (str_starts_with($type, 'enum-')) {
return 'enum';
}
$numberTypes = ['decimal', 'biginteger', 'integer', 'float', 'smallinteger', 'tinyinteger'];
if (in_array($type, $numberTypes, true)) {
return 'number';
Expand All @@ -258,6 +261,7 @@ public function getViewFieldsData(array $fields, SchemaInterface $schema, array
'number' => [],
'string' => [],
'boolean' => [],
'enum' => [],
'date' => [],
'text' => [],
];
Expand Down
4 changes: 3 additions & 1 deletion templates/bake/Template/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
{% endif %}
{% if isKey is not same as(true) %}
{% set columnData = Bake.columnData(field, schema) %}
{% if columnData.type not in ['integer', 'float', 'decimal', 'biginteger', 'smallinteger', 'tinyinteger'] %}
{% if columnData.type starts with 'enum-' %}
<td><?= h(${{ singularVar }}->{{ field }}->label()) ?></td>
{% elseif columnData.type not in ['integer', 'float', 'decimal', 'biginteger', 'smallinteger', 'tinyinteger'] %}
<td><?= h(${{ singularVar }}->{{ field }}) ?></td>
{% elseif columnData.null %}
<td><?= ${{ singularVar }}->{{ field }} === null ? '' : $this->Number->format(${{ singularVar }}->{{ field }}) ?></td>
Expand Down
13 changes: 13 additions & 0 deletions templates/bake/Template/view.twig
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@
</tr>
{% endfor %}
{% endif %}
{% if groupedFields.enum %}
{% for field in groupedFields.enum %}
<tr>
<th><?= __('{{ field|humanize }}') ?></th>
{% set columnData = Bake.columnData(field, schema) %}
{% if columnData.null %}
<td><?= ${{ singularVar }}->{{ field }} === null ? '' : h(${{ singularVar }}->{{ field }}->label()) ?></td>
{% else %}
<td><?= h(${{ singularVar }}->{{ field }}->label()) ?></td>
{% endif %}
</tr>
{% endfor %}
{% endif %}
{% if groupedFields.date %}
{% for field in groupedFields.date %}
<tr>
Expand Down

0 comments on commit 1df72e6

Please sign in to comment.