Skip to content

Commit

Permalink
Merge pull request #631 from cakephp/twigview-5
Browse files Browse the repository at this point in the history
Update templates for Twig 3 compatibility.
  • Loading branch information
dereuromark authored Dec 30, 2019
2 parents 91b20e2 + 5ee43ff commit 09a9b3e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"php": ">=7.2",
"cakephp/cakephp": "^4.0",
"cakephp/plugin-installer": "^1.0",
"wyrihaximus/twig-view": "dev-master"
"wyrihaximus/twig-view": "^5.0.1"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "~8.5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -52,7 +52,5 @@
"phpstan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan-shim:^0.11 && mv composer.backup composer.json",
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover=clover.xml"
},
"prefer-stable": true,
"minimum-stability": "dev"
}
}
6 changes: 4 additions & 2 deletions templates/bake/Model/table.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class {{ name }}Table extends Table
{%- for type, assocs in associations %}
{%- for assoc in assocs %}
{%- set assocData = [] %}
{%- for key, val in assoc if key is not same as('alias') %}
{%- set assocData = assocData|merge({(key): val}) %}
{%- for key, val in assoc %}
{%- if key is not same as('alias') %}
{%- set assocData = assocData|merge({(key): val}) %}
{%- endif %}
{%- endfor %}
$this->{{ type }}('{{ assoc.alias }}', [{{ Bake.stringifyList(assocData, {'indent': 3})|raw }}]);
{{- "\n" }}
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 @@ -40,9 +40,11 @@
{% for field in fields %}
{% set isKey = false %}
{% if associations.BelongsTo %}
{% for alias, details in associations.BelongsTo if field == details.foreignKey %}
{% for alias, details in associations.BelongsTo %}
{% if field == details.foreignKey %}
{% set isKey = true %}
<td><?= ${{ singularVar }}->has('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?></td>
{% endif %}
{% endfor %}
{% endif %}
{% if isKey is not same as(true) %}
Expand Down
26 changes: 14 additions & 12 deletions templates/bake/element/form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,27 @@
<fieldset>
<legend><?= __('{{ action|humanize }} {{ singularHumanName }}') ?></legend>
<?php
{% for field in fields if field not in primaryKey %}
{%- if keyFields[field] %}
{%- set fieldData = Bake.columnData(field, schema) %}
{%- if fieldData.null %}
{% for field in fields %}
{%- if field not in primaryKey %}
{%- if keyFields[field] %}
{%- set fieldData = Bake.columnData(field, schema) %}
{%- if fieldData.null %}
echo $this->Form->control('{{ field }}', ['options' => ${{ keyFields[field] }}, 'empty' => true]);
{{- "\n" }}
{%- else %}
{%- else %}
echo $this->Form->control('{{ field }}', ['options' => ${{ keyFields[field] }}]);
{{- "\n" }}
{%- endif %}
{%- elseif field not in ['created', 'modified', 'updated'] %}
{%- set fieldData = Bake.columnData(field, schema) %}
{%- if fieldData.type in ['date', 'datetime', 'time'] and fieldData.null %}
{%- endif %}
{%- elseif field not in ['created', 'modified', 'updated'] %}
{%- set fieldData = Bake.columnData(field, schema) %}
{%- if fieldData.type in ['date', 'datetime', 'time'] and fieldData.null %}
echo $this->Form->control('{{ field }}', ['empty' => true]);
{{- "\n" }}
{%- else %}
{%- else %}
echo $this->Form->control('{{ field }}');
{{- "\n" }}
{%- endif %}
{{- "\n" }}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
Expand Down

0 comments on commit 09a9b3e

Please sign in to comment.