chg: [metafields] Passed argument can either be an object or array

pull/93/head
Sami Mokaddem 2022-03-01 11:30:22 +01:00
parent bb94765243
commit 134b7bfc3e
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 5 additions and 6 deletions

View File

@ -2,7 +2,6 @@
namespace App\Model\Table;
use App\Model\Entity\MetaTemplateField;
use App\Model\Table\AppTable;
use Cake\ORM\Table;
use Cake\Validation\Validator;
@ -66,15 +65,15 @@ class MetaFieldsTable extends AppTable
return true;
}
public function isValidType($value, MetaTemplateField $metaTemplateField)
public function isValidType($value, $metaTemplateField)
{
if (empty($value)) {
return __('Metafield value cannot be empty.');
}
$typeHandler = $this->MetaTemplateFields->getTypeHandler($metaTemplateField->type);
$typeHandler = $this->MetaTemplateFields->getTypeHandler($metaTemplateField['type']);
if (!empty($typeHandler)) {
$success = $typeHandler->validate($value);
return $success ? true : __('Metafields value `{0}` for `{1}` doesn\'t pass type validation.', $value, $metaTemplateField->field);
return $success ? true : __('Metafields value `{0}` for `{1}` doesn\'t pass type validation.', $value, $metaTemplateField['field']);
}
/*
We should not end-up in this case. But if someone creates a new type without his handler,
@ -86,9 +85,9 @@ class MetaFieldsTable extends AppTable
public function isValidRegex($value, $metaTemplateField)
{
$re = $metaTemplateField->regex;
$re = $metaTemplateField['regex'];
if (!preg_match("/^$re$/m", $value)) {
return __('Metafield value `{0}` for `{1}` doesn\'t pass regex validation.', $value, $metaTemplateField->field);
return __('Metafield value `{0}` for `{1}` doesn\'t pass regex validation.', $value, $metaTemplateField['field']);
}
return true;
}