Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from Dolphiq/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
johanzandstra authored Mar 25, 2018
2 parents 13b2fb1 + 5c26c89 commit 80d1e69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -25,7 +25,7 @@
}
],
"require": {
"craftcms/cms": "^3.0.0-RC1"
"craftcms/cms": "^3.0.0-RC2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 0 additions & 2 deletions src/TitleEntriesFieldPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use craft\helpers\Json;


use craft\base\Object;

/**
* LinkFieldPlugin class.
*/
Expand Down
24 changes: 21 additions & 3 deletions src/fields/TitleEntriesField.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function isEmpty($value): bool
{
/** @var ElementQueryInterface $value */
// return $value->count() === 0;

return false;
}
/**
Expand All @@ -77,20 +77,38 @@ 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();
/** @var ElementQuery $query */
$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',
Expand Down

0 comments on commit 80d1e69

Please sign in to comment.