diff --git a/CHANGELOG.md b/CHANGELOG.md index f36c7c3..afd0e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog + +## 1.0.6 - 2018-03-25 + +### Fixed +- Fixed a bug in PHP 7.2 including the common class name Object + ## 1.0.5 - 2017-12-18 - Quick fix, working on a long-term fix! - Fixes issues with the field in Craft RC2 diff --git a/composer.json b/composer.json index 7d5b667..89ff4da 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "dolphiq/titleentriesfield", "description": "Offers users a field type with an easy way to set a different title for the relation than the related page title. Useful in menus, submenus or related lists if you are linking to other content but want to use shorter or different titles in the lists.", "type": "craft-plugin", - "version": "1.0.5", + "version": "1.0.6", "keywords": [ "craft", "cms", @@ -25,7 +25,7 @@ } ], "require": { - "craftcms/cms": "^3.0.0-RC1" + "craftcms/cms": "^3.0.0-RC2" }, "autoload": { "psr-4": { diff --git a/src/TitleEntriesFieldPlugin.php b/src/TitleEntriesFieldPlugin.php index 2ee5e97..11ad64e 100644 --- a/src/TitleEntriesFieldPlugin.php +++ b/src/TitleEntriesFieldPlugin.php @@ -21,8 +21,6 @@ use craft\helpers\Json; -use craft\base\Object; - /** * LinkFieldPlugin class. */ diff --git a/src/fields/TitleEntriesField.php b/src/fields/TitleEntriesField.php index ee9870a..6856814 100644 --- a/src/fields/TitleEntriesField.php +++ b/src/fields/TitleEntriesField.php @@ -52,7 +52,7 @@ public function isEmpty($value): bool { /** @var ElementQueryInterface $value */ // return $value->count() === 0; - + return false; } /** @@ -77,7 +77,7 @@ public function normalizeValue($value, ElementInterface $element = null) if ($value instanceof ElementQueryInterface) { return $value; } - + // return false;var_dump($value); /** @var Element|null $element */ /** @var Element $class */ $class = static::elementType(); @@ -85,12 +85,30 @@ public function normalizeValue($value, ElementInterface $element = null) $query = $class::find() ->siteId($this->targetSiteId($element)); + + if(is_array($value)) { + $is_json = false; + $new_values = []; + foreach ($value as $sortOrder => $targetElement) { + + if (is_string($targetElement) && strpos($targetElement, '{') !== false) { + $targetElement = Json::decode($targetElement); + $new_values[$sortOrder] = $targetElement['id']; + $is_json = true; + } + } + if ($is_json) { + + } + } + + // $value will be an array of element IDs if there was a validation error or we're loading a draft/version. if (is_array($value)) { $query ->id(array_values(array_filter($value))) ->fixedOrder(); - } else if ($value !== '' && $element && $element->id) { + } else if (($value === NULL || $value !== '') && $element && $element->id) { $query->innerJoin( '{{%relations}} relations',