From fd6458fecd9f2e96b31190e7fbef306b66ad601b Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Fri, 3 May 2024 13:24:53 +0100 Subject: [PATCH] matching elements on custom fields --- src/elements/CalenderEvent.php | 10 ++++++---- src/elements/Category.php | 5 +++-- src/elements/Entry.php | 15 +++++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/elements/CalenderEvent.php b/src/elements/CalenderEvent.php index cb3f25bb..35ef0180 100644 --- a/src/elements/CalenderEvent.php +++ b/src/elements/CalenderEvent.php @@ -217,10 +217,12 @@ protected function parseAuthorId($feedData, $fieldInfo): ?int if ($match === 'fullName') { $element = UserElement::findOne(['search' => $value, 'status' => null]); } else { - $element = UserElement::find() - ->status(null) - ->andWhere(['=', $match, $value]) - ->one(); + $query = UserElement::find() + ->status(null); + + // using $query->andWhere() doesn't work for custom fields + Craft::configure($query, [$match => $value]); + $element = $query->one(); } if ($element) { diff --git a/src/elements/Category.php b/src/elements/Category.php index c0631e5f..1c100566 100644 --- a/src/elements/Category.php +++ b/src/elements/Category.php @@ -155,8 +155,7 @@ protected function parseParent($feedData, $fieldInfo): ?int } $query = CategoryElement::find() - ->status(null) - ->andWhere(['=', $match, $value]); + ->status(null); if (isset($this->feed['siteId']) && $this->feed['siteId']) { $query->siteId($this->feed['siteId']); @@ -167,6 +166,8 @@ protected function parseParent($feedData, $fieldInfo): ?int $query->groupId($this->element->groupId); } + // using $query->andWhere() doesn't work for custom fields + Craft::configure($query, [$match => $value]); $element = $query->one(); if ($element) { diff --git a/src/elements/Entry.php b/src/elements/Entry.php index 7e39c84e..4798d184 100644 --- a/src/elements/Entry.php +++ b/src/elements/Entry.php @@ -247,8 +247,7 @@ protected function parseParent($feedData, $fieldInfo): ?int } $query = EntryElement::find() - ->status(null) - ->andWhere(['=', $match, $value]); + ->status(null); if (isset($this->feed['siteId']) && $this->feed['siteId']) { $query->siteId($this->feed['siteId']); @@ -259,6 +258,8 @@ protected function parseParent($feedData, $fieldInfo): ?int $query->sectionId($this->element->sectionId); } + // using $query->andWhere() doesn't work for custom fields + Craft::configure($query, [$match => $value]); $element = $query->one(); if ($element) { @@ -326,10 +327,12 @@ protected function parseAuthorIds($feedData, $fieldInfo): ?array if ($match === 'fullName') { $element = UserElement::findOne(['search' => $value, 'status' => null]); } else { - $element = UserElement::find() - ->status(null) - ->andWhere(['=', $match, $value]) - ->one(); + $query = UserElement::find() + ->status(null); + + // using $query->andWhere() doesn't work for custom fields + Craft::configure($query, [$match => $value]); + $element = $query->one(); } if ($element) {