From 5ee43ffc612b34e6cee281f01d69f9a42da2d89e Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 30 Dec 2019 16:47:10 +0530 Subject: [PATCH] Use TwigView v5. --- composer.json | 8 +++----- templates/bake/Model/table.twig | 6 ++++-- templates/bake/Template/index.twig | 4 +++- templates/bake/element/form.twig | 26 ++++++++++++++------------ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 589b3c16f..1f94f521f 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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" + } } diff --git a/templates/bake/Model/table.twig b/templates/bake/Model/table.twig index 72cd36d24..38ce7a237 100644 --- a/templates/bake/Model/table.twig +++ b/templates/bake/Model/table.twig @@ -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" }} diff --git a/templates/bake/Template/index.twig b/templates/bake/Template/index.twig index e6fe0fee8..3829e27df 100644 --- a/templates/bake/Template/index.twig +++ b/templates/bake/Template/index.twig @@ -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 %} has('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?> +{% endif %} {% endfor %} {% endif %} {% if isKey is not same as(true) %} diff --git a/templates/bake/element/form.twig b/templates/bake/element/form.twig index 17f3c18b7..76dddbabd 100644 --- a/templates/bake/element/form.twig +++ b/templates/bake/element/form.twig @@ -36,25 +36,27 @@
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 %}