fix: [behavior:metafields] Switch to text filtering if meta-template-field is not provided

pull/93/head
Sami Mokaddem 2022-02-28 10:49:34 +01:00
parent 7d345f98f2
commit 4b95b49854
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 3 additions and 3 deletions

View File

@ -239,7 +239,7 @@ class MetaFieldsBehavior extends Behavior
protected function buildQuerySnippet(array $filter): Query
{
$this->MetaTemplateFields = TableRegistry::getTableLocator()->get('MetaTemplateFields');
$metaTemplateField = $this->MetaTemplateFields->get($filter['meta_template_field_id']);
$metaTemplateField = !empty($filter['meta_template_field_id']) ? $this->MetaTemplateFields->get($filter['meta_template_field_id']) : null;
$whereClosure = function (QueryExpression $exp) use ($filter, $metaTemplateField) {
foreach ($filter as $column => $value) {
$keyedColumn = 'MetaFields.' . $column;
@ -259,9 +259,9 @@ class MetaFieldsBehavior extends Behavior
return $query;
}
protected function setQueryExpressionForField(QueryExpression $exp, string $field, string $value, \App\Model\Entity\MetaTemplateField $metaTemplateField): QueryExpression
protected function setQueryExpressionForField(QueryExpression $exp, string $field, string $value, \App\Model\Entity\MetaTemplateField $metaTemplateField=null): QueryExpression
{
if (isset($this->typeHandlers[$metaTemplateField->type])) {
if (!is_null($metaTemplateField) && isset($this->typeHandlers[$metaTemplateField->type])) {
$exp = $this->typeHandlers[$metaTemplateField->type]->setQueryExpression($exp, $value, $metaTemplateField);
} else {
$exp = $this->setQueryExpressionForTextField($exp, $field, $value);