= $this->Text->autoParagraph(h(${{ singularVar }}->{{ field }})); ?>
diff --git a/templates/bake/Controller/controller.twig b/templates/bake/Controller/controller.twig index 83a843e1..3212114f 100644 --- a/templates/bake/Controller/controller.twig +++ b/templates/bake/Controller/controller.twig @@ -32,7 +32,7 @@ {% endif %} {%- for component in components %} -{% set classInfo = Bake.classInfo(component, 'Controller/Component', 'Component') %} + {%~ set classInfo = Bake.classInfo(component, 'Controller/Component', 'Component') %} * @property {{ classInfo.fqn }} ${{ classInfo.name }} {% endfor %} */ @@ -48,20 +48,20 @@ class {{ name }}Controller extends AppController { parent::initialize(); -{% for component in components %} + {%~ for component in components %} $this->loadComponent('{{ component }}'); -{% endfor %} -{% if helpers %} + {%~ endfor %} + {%~ if helpers %} $this->viewBuilder()->setHelpers({{ Bake.exportArray(helpers)|raw }}); -{% endif %} -{% if has_login %} + {%~ endif %} + {%~ if has_login %} $this->Authentication->allowUnauthenticated(['login']); -{% endif %} + {%~ endif %} } -{% if actions|length %}{{ "\n" }}{% endif %} + {%~ if actions|length %}{{ "\n" }}{% endif %} {% endif %} -{%- for action in actions %} -{% if loop.index > 1 %}{{ "\n" }}{% endif %} +{% for action in actions %} + {%~ if loop.index > 1 %}{{ "\n" }}{% endif %} {{- element('Bake.Controller/' ~ action) -}} {% endfor %} } diff --git a/templates/bake/Model/entity.twig b/templates/bake/Model/entity.twig index 0885b7fc..ab924dd7 100644 --- a/templates/bake/Model/entity.twig +++ b/templates/bake/Model/entity.twig @@ -18,8 +18,8 @@ {% set annotations = DocBlock.propertyHints(propertyHintMap) %} {%- if associationHintMap %} - {%- set annotations = annotations|merge(['']) %} - {%- set annotations = annotations|merge(DocBlock.propertyHints(associationHintMap)) %} + {%~ set annotations = annotations|merge(['']) %} + {%~ set annotations = annotations|merge(DocBlock.propertyHints(associationHintMap)) %} {% endif %} {%- set accessible = Bake.getFieldAccessibility(fields, primaryKey) %} @@ -39,7 +39,7 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem {% endif %} {% if accessible %} -{%- set generatedProperties = generatedProperties|merge(['_accessible']) %} +{%~ set generatedProperties = generatedProperties|merge(['_accessible']) %} /** * Fields that can be mass assigned using newEntity() or patchEntity(). * @@ -54,8 +54,8 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem {% if accessible and hidden %} {% endif %} -{%- if hidden %} -{%- set generatedProperties = generatedProperties|merge(['_hidden']) %} +{% if hidden %} + {%~ set generatedProperties = generatedProperties|merge(['_hidden']) %} /** * Fields that are excluded from JSON versions of the entity. * diff --git a/templates/bake/Model/table.twig b/templates/bake/Model/table.twig index acd786fa..3a9624af 100644 --- a/templates/bake/Model/table.twig +++ b/templates/bake/Model/table.twig @@ -50,58 +50,43 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im {%- if displayField %} $this->setDisplayField({{ (displayField is iterable ? Bake.exportArray(displayField) : Bake.exportVar(displayField))|raw }}); {% endif %} - -{%- if primaryKey %} - {%- if primaryKey is iterable and primaryKey|length > 1 %} +{% if primaryKey %} + {%~ if primaryKey is iterable and primaryKey|length > 1 %} $this->setPrimaryKey({{ Bake.exportArray(primaryKey)|raw }}); - {{- "\n" }} - {%- else %} + {%~ else %} $this->setPrimaryKey('{{ primaryKey|as_array|first }}'); - {{- "\n" }} - {%- endif %} + {%~ endif %} {% endif %} +{% if enums %} -{%- if enums %} - -{% endif %} - -{%- if enums %} - -{%- for name, className in enums %} + {%~ for name, className in enums %} $this->getSchema()->setColumnType('{{ name }}', \Cake\Database\Type\EnumType::from(\{{ className }}::class)); -{% endfor %} + {%~ endfor %} {% endif %} +{% if behaviors %} -{%- if behaviors %} - -{% endif %} - -{%- for behavior, behaviorData in behaviors %} + {%~ for behavior, behaviorData in behaviors %} $this->addBehavior('{{ behavior }}'{{ (behaviorData ? (", " ~ Bake.exportArray(behaviorData, 2)|raw ~ '') : '')|raw }}); -{% endfor %} - -{%- if associations.belongsTo or associations.hasMany or associations.belongsToMany %} - + {%~ endfor %} {% endif %} - -{%- 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}) %} - {%- endif %} - {%- endfor %} +{% if associations.belongsTo or associations.hasMany or associations.belongsToMany %} + + {%~ 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}) %} + {%~ endif %} + {%~ endfor %} $this->{{ type }}('{{ assoc.alias }}', {{ Bake.exportArray(assocData, 2)|raw }}); - {{- "\n" }} - {%- endfor %} -{% endfor %} + {%~ endfor %} + {%~ endfor %} +{% endif %} } -{{- "\n" }} - -{%- if validation %} -{% set generatedFunctions = generatedFunctions|merge(['validationDefault']) %} +{% if validation %} + {%~ set generatedFunctions = generatedFunctions|merge(['validationDefault']) %} /** * Default validation rules. * @@ -110,25 +95,24 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im */ public function validationDefault(Validator $validator): Validator { -{% for field, rules in validation %} -{% set validationMethods = Bake.getValidationMethods(field, rules) %} -{% if validationMethods %} + {%~ for field, rules in validation %} + {%~ set validationMethods = Bake.getValidationMethods(field, rules) %} + {%~ if validationMethods %} $validator -{% for validationMethod in validationMethods %} -{% if loop.last %} -{% set validationMethod = validationMethod ~ ';' %} -{% endif %} + {%~ for validationMethod in validationMethods %} + {%~ if loop.last %} + {%~ set validationMethod = validationMethod ~ ';' %} + {%~ endif %} {{ validationMethod|raw }} -{% endfor %} + {%~ endfor %} -{% endif %} -{% endfor %} + {%~ endif %} + {%~ endfor %} return $validator; } {% endif %} - {%- if rulesChecker %} -{% set generatedFunctions = generatedFunctions|merge(['buildRules']) %} + {%~ set generatedFunctions = generatedFunctions|merge(['buildRules']) %} /** * Returns a rules checker object that will be used for validating @@ -139,21 +123,20 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im */ public function buildRules(RulesChecker $rules): RulesChecker { -{% for rule in rulesChecker %} -{% set fields = Bake.exportArray(rule.fields) %} -{% set options = '' %} -{% for optionName, optionValue in rule.options %} - {%~ set options = (loop.first ? '[' : options) ~ "'#{optionName}' => " ~ Bake.exportVar(optionValue) ~ (loop.last ? ']' : ', ') %} -{% endfor %} + {%~ for rule in rulesChecker %} + {%~ set fields = Bake.exportArray(rule.fields) %} + {%~ set options = '' %} + {%~ for optionName, optionValue in rule.options %} + {%~ set options = (loop.first ? '[' : options) ~ "'#{optionName}' => " ~ Bake.exportVar(optionValue) ~ (loop.last ? ']' : ', ') %} + {%~ endfor %} $rules->add($rules->{{ rule.name }}({{ fields|raw }}{{ (rule.extra|default ? ", '#{rule.extra}'" : '')|raw }}{{ (options ? ', ' ~ options : '')|raw }}), ['errorField' => '{{ rule.fields[0] }}']); -{% endfor %} + {%~ endfor %} return $rules; } {% endif %} - -{%- if connection is not same as('default') %} -{% set generatedFunctions = generatedFunctions|merge(['defaultConnectionName']) %} +{% if connection is not same as('default') %} + {%~ set generatedFunctions = generatedFunctions|merge(['defaultConnectionName']) %} /** * Returns the database connection name to use by default. diff --git a/templates/bake/Template/add.twig b/templates/bake/Template/add.twig index c21d7c1d..bfbfcbad 100644 --- a/templates/bake/Template/add.twig +++ b/templates/bake/Template/add.twig @@ -17,18 +17,15 @@ /** * @var \{{ namespace }}\View\AppView $this * @var \{{ entityClass }} ${{ singularVar }} - {{- "\n" }} -{%- if associations.BelongsTo is defined %} - {%- for assocName, assocData in associations.BelongsTo %} +{% if associations.BelongsTo is defined %} + {%~ for assocName, assocData in associations.BelongsTo %} * @var \Cake\Collection\CollectionInterface|string[] ${{ assocData.variable }} - {{- "\n" }} - {%- endfor %} + {%~ endfor %} {% endif %} -{%- if associations.BelongsToMany is defined %} - {%- for assocName, assocData in associations.BelongsToMany %} +{% if associations.BelongsToMany is defined %} + {%~ for assocName, assocData in associations.BelongsToMany %} * @var \Cake\Collection\CollectionInterface|string[] ${{ assocData.variable }} - {{- "\n" }} - {%- endfor %} + {%~ endfor %} {% endif %} */ ?> diff --git a/templates/bake/Template/edit.twig b/templates/bake/Template/edit.twig index 90fed4ec..a7d57e8f 100644 --- a/templates/bake/Template/edit.twig +++ b/templates/bake/Template/edit.twig @@ -17,18 +17,15 @@ /** * @var \{{ namespace }}\View\AppView $this * @var \{{ entityClass }} ${{ singularVar }} - {{- "\n" }} -{%- if associations.BelongsTo is defined %} - {%- for assocName, assocData in associations.BelongsTo %} +{% if associations.BelongsTo is defined %} + {%~ for assocName, assocData in associations.BelongsTo %} * @var string[]|\Cake\Collection\CollectionInterface ${{ assocData.variable }} - {{- "\n" }} - {%- endfor %} + {%~ endfor %} {% endif %} -{%- if associations.BelongsToMany is defined %} - {%- for assocName, assocData in associations.BelongsToMany %} +{% if associations.BelongsToMany is defined %} + {%~ for assocName, assocData in associations.BelongsToMany %} * @var string[]|\Cake\Collection\CollectionInterface ${{ assocData.variable }} - {{- "\n" }} - {%- endfor %} + {%~ endfor %} {% endif %} */ ?> diff --git a/templates/bake/Template/index.twig b/templates/bake/Template/index.twig index 7cab8aa1..4a81b76f 100644 --- a/templates/bake/Template/index.twig +++ b/templates/bake/Template/index.twig @@ -38,28 +38,28 @@
| = __('{{ details.property|humanize }}') ?> | = ${{ singularVar }}->hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?> | |
|---|---|---|
| = __('{{ field|humanize }}') ?> | = h(${{ singularVar }}->{{ field }}) ?> | |
| = __('{{ alias|underscore|singularize|humanize }}') ?> | = ${{ singularVar }}->hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?> | |
| = __('{{ field|humanize }}') ?> | -{% set columnData = Bake.columnData(field, schema) %} -{% if columnData.null %} + {%~ set columnData = Bake.columnData(field, schema) %} + {%~ if columnData.null %}= ${{ singularVar }}->{{ field }} === null ? '' : $this->Number->format(${{ singularVar }}->{{ field }}) ?> | -{% else %} + {%~ else %}= $this->Number->format(${{ singularVar }}->{{ field }}) ?> | -{% endif %} + {%~ endif %}
| = __('{{ field|humanize }}') ?> | -{% set columnData = Bake.columnData(field, schema) %} -{% set supportsLabel = Bake.enumSupportsLabel(field, schema) %} -{% if columnData.null %} + {%~ set columnData = Bake.columnData(field, schema) %} + {%~ set supportsLabel = Bake.enumSupportsLabel(field, schema) %} + {%~ if columnData.null %}= ${{ singularVar }}->{{ field }} === null ? '' : h(${{ singularVar }}->{{ field }}->{% if supportsLabel %}label(){% else %}value{% endif %}) ?> | -{% else %} + {%~ else %}= h(${{ singularVar }}->{{ field }}->{% if supportsLabel %}label(){% else %}value{% endif %}) ?> | -{% endif %} + {%~ endif %}
| = __('{{ field|humanize }}') ?> | = h(${{ singularVar }}->{{ field }}) ?> | |
| = __('{{ field|humanize }}') ?> | = ${{ singularVar }}->{{ field }} ? __('Yes') : __('No'); ?> |
= $this->Text->autoParagraph(h(${{ singularVar }}->{{ field }})); ?>