Skip to content

Commit

Permalink
Merge pull request #700 from cakephp/app-rules
Browse files Browse the repository at this point in the history
Generate application rules with error field.
  • Loading branch information
markstory authored Aug 1, 2020
2 parents f6d3eb5 + 3cec9a6 commit 4f723a5
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion templates/bake/Model/table.twig
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class {{ name }}Table extends Table
public function buildRules(RulesChecker $rules): RulesChecker
{
{% for field, rule in rulesChecker %}
$rules->add($rules->{{ rule.name }}(['{{ field }}']{{ (rule.extra is defined and rule.extra ? (", '#{rule.extra}'") : '')|raw }}));
$rules->add($rules->{{ rule.name }}(['{{ field }}']{{ (rule.extra is defined and rule.extra ? (", '#{rule.extra}'") : '')|raw }}), ['errorField' => '{{ field }}']);
{% endfor %}
return $rules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function initialize(array $config): void
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['category_id'], 'Categories'));
$rules->add($rules->existsIn(['product_id'], 'Products'));
$rules->add($rules->existsIn(['category_id'], 'Categories'), ['errorField' => 'category_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);

return $rules;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function validationDefault(Validator $validator): Validator
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_id'], 'Products'));
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);

return $rules;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function validationDefault(Validator $validator): Validator
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_id'], 'Products'));
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeEntityWithPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function initialize(array $config): void
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['username']));
$rules->add($rules->isUnique(['username']), ['errorField' => 'username']);

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeTableConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function validationDefault(Validator $validator): Validator
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['user_id'], 'Users'));
$rules->add($rules->existsIn(['user_id'], 'Users'), ['errorField' => 'user_id']);

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeTableWithCounterCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function initialize(array $config): void
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['todo_item_id'], 'TodoItems'));
$rules->add($rules->existsIn(['todo_item_id'], 'TodoItems'), ['errorField' => 'todo_item_id']);

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeTableWithPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function initialize(array $config): void
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['username']));
$rules->add($rules->isUnique(['username']), ['errorField' => 'username']);

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeWithRulesUnique.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function validationDefault(Validator $validator): Validator
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['username']));
$rules->add($rules->isUnique(['username']), ['errorField' => 'username']);

return $rules;
}
Expand Down

0 comments on commit 4f723a5

Please sign in to comment.