Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions templates/bake/Controller/controller.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
*/
Expand All @@ -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 %}
}
10 changes: 5 additions & 5 deletions templates/bake/Model/entity.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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) %}
Expand All @@ -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().
*
Expand All @@ -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.
*
Expand Down
107 changes: 45 additions & 62 deletions templates/bake/Model/table.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
Expand All @@ -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.
Expand Down
15 changes: 6 additions & 9 deletions templates/bake/Template/add.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
*/
?>
Expand Down
15 changes: 6 additions & 9 deletions templates/bake/Template/edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
*/
?>
Expand Down
34 changes: 17 additions & 17 deletions templates/bake/Template/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@
<?php foreach (${{ pluralVar }} as ${{ singularVar }}): ?>
<tr>
{% for field in fields %}
{% set isKey = false %}
{% if associations.BelongsTo is defined %}
{% for alias, details in associations.BelongsTo %}
{% if field == details.foreignKey %}
{% set isKey = true %}
{%~ set isKey = false %}
{%~ if associations.BelongsTo is defined %}
{%~ for alias, details in associations.BelongsTo %}
{%~ if field == details.foreignKey %}
{%~ set isKey = true %}
<td><?= ${{ singularVar }}->hasValue('{{ 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) %}
{% set columnData = Bake.columnData(field, schema) %}
{% set supportsLabel = Bake.enumSupportsLabel(field, schema) %}
{% if columnData.type starts with 'enum-' %}
{%~ endif %}
{%~ endfor %}
{%~ endif %}
{%~ if isKey is not same as(true) %}
{%~ set columnData = Bake.columnData(field, schema) %}
{%~ set supportsLabel = Bake.enumSupportsLabel(field, schema) %}
{%~ if columnData.type starts with 'enum-' %}
<td><?= ${{ singularVar }}->{{ field }} === null ? '' : h(${{ singularVar }}->{{ field }}->{% if supportsLabel %}label(){% else %}value{% endif %}) ?></td>
{% elseif columnData.type not in ['integer', 'float', 'decimal', 'biginteger', 'smallinteger', 'tinyinteger'] %}
{%~ elseif columnData.type not in ['integer', 'float', 'decimal', 'biginteger', 'smallinteger', 'tinyinteger'] %}
<td><?= h(${{ singularVar }}->{{ field }}) ?></td>
{% elseif columnData.null %}
{%~ elseif columnData.null %}
<td><?= ${{ singularVar }}->{{ field }} === null ? '' : $this->Number->format(${{ singularVar }}->{{ field }}) ?></td>
{% else %}
{%~ else %}
<td><?= $this->Number->format(${{ singularVar }}->{{ field }}) ?></td>
{% endif %}
{% endif %}
{%~ endif %}
{%~ endif %}
{% endfor %}
{% set pk = '$' ~ singularVar ~ '->' ~ primaryKey[0] %}
<td class="actions">
Expand Down
Loading