Skip to content

Commit

Permalink
fix error parsing in StandardController
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 3, 2025
1 parent 3970cf6 commit 131bf5c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use App\Lib\Traits\IndexQueryTrait;
use Cake\Database\Expression\QueryExpression;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use \App\Lib\Enum\ProvisioningContextEnum;
Expand Down Expand Up @@ -61,6 +62,8 @@ public function add() {
$table = $this->$modelsName;
// $tableName = models
$tableName = $table->getTable();
// Schema
$schema = $table->getSchema();
// Create an empty entity for FormHelper
$obj = $table->newEmptyEntity();

Expand Down Expand Up @@ -97,14 +100,12 @@ public function add() {

if(!empty($errors)) {
$errorlist = [];
foreach ($errors as $model => $fails) {
foreach ($fails as $issues) {
foreach ($issues as $column => $issue) {
$error_descriptions = array_values($issue);
$col_issues = implode(',', $error_descriptions);
$errorlist[] = __d('error', 'flash', [$column, $col_issues]);
}
}
$errorsParsed = Hash::flatten($errors);
foreach ($errorsParsed as $struct => $issue) {
$partials = explode('.', $struct);
// Try to find the column
$column = collection($partials)->filter(fn($partial) => $schema->getColumn($partial) !== null)->first();
$errorlist[] = __d('error', 'flash', [$column, $issue]);
}
$this->Flash->error(__d('error', 'fields', $errorlist));
} else {
Expand Down

0 comments on commit 131bf5c

Please sign in to comment.