chg: [metaFields] Clean-up and improved regex matching

pull/93/head
Sami Mokaddem 2021-11-23 15:30:37 +01:00
parent 87ac0f7569
commit 4acf5209c8
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 3 additions and 17 deletions

View File

@ -59,22 +59,6 @@ class MetaFieldsTable extends AppTable
return true;
}
public function isValidMetaFieldOLD($entity, $options)
{
debug($entity['value']);
$metaFieldsTable = $options['repository'];
$metaTemplateField = $metaFieldsTable->MetaTemplateFields->get($entity['meta_template_field_id']);
$typeValid = $this->isValidType($entity['value'], $metaTemplateField['type']);
if ($typeValid !== true) {
return $typeValid;
}
$metaTemplateField['regex'] = '/123/';
if (!empty($metaTemplateField['regex'])) {
return $this->isValidRegex($entity['value'], $metaTemplateField);
}
return true;
}
public function isValidType($value, string $type)
{
if (empty($value)) {
@ -85,7 +69,9 @@ class MetaFieldsTable extends AppTable
public function isValidRegex($value, $metaTemplateField)
{
if (!preg_match($metaTemplateField['regex'], $value)) {
$re = $metaTemplateField['regex'];
if (!preg_match("/^$re$/m", $value)) {
return __('Metafield value `{0}` for `{1}` doesn\'t pass regex validation', $value, $metaTemplateField->field);
}
return true;