From af08aa9dd7e5d79cd750f03015164a443797d57e Mon Sep 17 00:00:00 2001 From: Sam Hibberd Date: Wed, 24 Aug 2022 22:09:41 +0100 Subject: [PATCH] Fix Eager Loading --- CHANGELOG.md | 161 ++++++++++++++++++++----------------------------- composer.json | 2 +- src/Linkit.php | 9 ++- 3 files changed, 75 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8178921..73b41ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,203 +1,176 @@ # Linkit Changelog > One link field to rule them all, built for [Craft 3](http://craftcms.com) +## 3.0.1 - 2022-08-24 + +### Fixed +- Fixed error caused by eager loading for elements with multiple entry types / field layouts ([#102](https://github.com/presseddigital/linkit/issues/102)) + ## 3.0.0 - 2022-07-13 > {warning} Breaking Change - GQL users, support for querying subfields may mean you need to update and queries that work with linkit fields. ### Changed - -* Transfer ownership to Pressed Digital -* Bump version numbers to mirror crafts major versions -* Remove LinkitHelper -* getLink() now uses the craft `Html::tag()` to build links and correctly handles any custom attributes -* Improve attribute methods for the base link -* Removed whitespace from the phone url [#74] -* Corrected LinkedIn spelling [#62] +- Transfer ownership to Pressed Digital +- Bump version numbers to mirror crafts major versions +- Remove LinkitHelper +- getLink() now uses the craft `Html::tag()` to build links and correctly handles any custom attributes +- Improve attribute methods for the base link +- Removed whitespace from the phone url ([#74](https://github.com/presseddigital/linkit/issues/74)) +- Corrected LinkedIn spelling ([#62](https://github.com/presseddigital/linkit/issues/62)) ### Added - -* Support for querying subfields with GraphQL. [#69] [#96] Thanks to @peaffenzeller. -* Eager loading support [#89] - -[#74]: https://github.com/presseddigital/linkit/issues/74 -[#69]: https://github.com/presseddigital/linkit/issues/69 -[#96]: https://github.com/presseddigital/linkit/issues/96 -[#89]: https://github.com/presseddigital/linkit/issues/89 -[#62]: https://github.com/presseddigital/linkit/issues/62 +- Support for querying subfields with GraphQL. ([#69](https://github.com/presseddigital/linkit/issues/69)) ([#96](https://github.com/presseddigital/linkit/issues/96)) Thanks to @peaffenzeller. +- Eager loading support ([#89](https://github.com/presseddigital/linkit/issues/89)) ## 1.1.12.1 - 2020-10-29 ## 1.1.12 - 2020-10-29 ### Fixed - -* Fixed site menu dropdown option for entry selection. Credit to @renzo-s. +- Fixed site menu dropdown option for entry selection. Credit to @renzo-s. ## 1.1.11 - 2019-04-03 ### Fixed - -* Fixed migration issue with Schema Checks & Mute events. Credit to @andris-sevcenko again. +- Fixed migration issue with Schema Checks & Mute events. Credit to @andris-sevcenko again. ## 1.1.10 - 2019-03-19 ### Fixed - -* Fixed Craft 2 migration (findgers crossed for good) addressing issues with element sources and linkit fields nested in Matrix or Super Table. Thanks again @andris-sevcenko. -* Fixed SuperTable Craft 2 migration issue where Linkit is installed before SuperTable during upgrade. -* Fixed migration of Element sources converting IDs to UIDs. -* Fixed custom link docs (Thanks @domstubbs) +- Fixed Craft 2 migration (findgers crossed for good) addressing issues with element sources and linkit fields nested in Matrix or Super Table. Thanks again @andris-sevcenko. +- Fixed SuperTable Craft 2 migration issue where Linkit is installed before SuperTable during upgrade. +- Fixed migration of Element sources converting IDs to UIDs. +- Fixed custom link docs (Thanks @domstubbs) ## 1.1.9 - 2019-03-02 ### Fixed - -* Fixed migration issue where Super Table was not setting a type value on a field. Thanks @olibon. +- Fixed migration issue where Super Table was not setting a type value on a field. Thanks @olibon. ### Changed - -* Improved migration scripts (Thanks to @roelvanhintum's input) +- Improved migration scripts (Thanks to @roelvanhintum's input) ## 1.1.8 - 2019-02-08 ### Changed - -* Changed migration scripts as per Crafts new recommendations (Thanks to @andris-sevcenko) -* Changed requires Craft 3.1.2+ -* Changed README.md installation instructions +- Changed migration scripts as per Crafts new recommendations (Thanks to @andris-sevcenko) +- Changed requires Craft 3.1.2+ +- Changed README.md installation instructions ### Fixed - -* Fixed some README.md typos +- Fixed some README.md typos ### Added - -* Added `{{ customText }}` info to the docs +- Added `{{ customText }}` info to the docs ## 1.1.6 - 2019-01-17 ### Fixed - -* Fixed Craft 2 migration error preventing install on Craft 3.1.x -* Removed some unused template tags -* Fixed issues bug on the about page +- Fixed Craft 2 migration error preventing install on Craft 3.1.x +- Removed some unused template tags +- Fixed issues bug on the about page ## 1.1.5.1 - 2019-01-15 ### Fixed - -* Fixed Changelog date +- Fixed Changelog date ## 1.1.5 - 2019-01-14 ### Added - -* Added support for @web alias in the URL link type -* Added support for mailto links in the URL link type -* Added settings to control whether the URL link type allows hashes, mailto, aliases or paths +- Added support for @web alias in the URL link type +- Added support for mailto links in the URL link type +- Added settings to control whether the URL link type allows hashes, mailto, aliases or paths ## 1.1.4 - 2018-10-23 ### Fixed - -* Fixed some recursive infinite loop issues and Solpace Calendar crashes (All credit goes to Craft's Brad Bell) +- Fixed some recursive infinite loop issues and Solpace Calendar crashes (All credit goes to Craft's Brad Bell) ## 1.1.3 - 2018-09-28 ### Changed - -* Changed - Version bump +- Changed - Version bump ## 1.1.2 - 2018-09-28 ### Changed - -* Changed - Plugin icon +- Changed - Plugin icon ## 1.1.1 - 2018-08-23 ### Fixed - -* Fixed a couple of changelog typos :) +- Fixed a couple of changelog typos :) ## 1.1.0 - 2018-08-23 ### Changed - -* Changed - Improved Linked In link validation -* Changed - Improved url link validation -* Changed - Element link types now allowed to select disabled elements to match the first party Craft element fieldtypes -* Changed - Updated element select to match first party fields -* Changed - Improved support for multisite setup +- Changed - Improved Linked In link validation +- Changed - Improved url link validation +- Changed - Element link types now allowed to select disabled elements to match the first party Craft element fieldtypes +- Changed - Updated element select to match first party fields +- Changed - Improved support for multisite setup ### Added - -* Added `hasElement()` method to link models to quickly determine if the link is an element link type -* Added `isAvailable()` method to link models to quickly determine if a link is available -* Added setting to override the default placeholder text for basic and social link types -* Added `getTableAttributeHtmlLink()` method, Linkit fields are now previewable table columns in table view -* Added status indicators to preview to determine if a link is available +- Added `hasElement()` method to link models to quickly determine if the link is an element link type +- Added `isAvailable()` method to link models to quickly determine if a link is available +- Added setting to override the default placeholder text for basic and social link types +- Added `getTableAttributeHtmlLink()` method, Linkit fields are now previewable table columns in table view +- Added status indicators to preview to determine if a link is available ### Fixed - -* Fixed issue with the Craft 2 normailize function when a type is not specified -* Fixed cp translation bug on element link types when using multiple sites -* Fixed an issue with the Craft 2 > Craft 3 migration script related to an undefined type index +- Fixed issue with the Craft 2 normailize function when a type is not specified +- Fixed cp translation bug on element link types when using multiple sites +- Fixed an issue with the Craft 2 > Craft 3 migration script related to an undefined type index ## 1.0.8 - 2018-04-24 ### Fixed - -* Fixed element select - now respects selected site in the cp +- Fixed element select - now respects selected site in the cp ## 1.0.7.1 - 2018-04-24 ### Added - -* Fixed version issue +- Fixed version issue ## 1.0.7 - 2018-04-24 ### Added - -* Added Craft 2 migration scripts -* Added product link type (requires the awesome Craft Commerce) +- Added Craft 2 migration scripts +- Added product link type (requires the awesome Craft Commerce) ### Fixed - -* Fixed email & phone links text value returning the full url -* Fixed documentation link +- Fixed email & phone links text value returning the full url +- Fixed documentation link ## 1.0.6 - 2018-04-16 ### Fixed - -* Fixed the select toggle where there is multiple Linkit field's on the same layout -* Fixed the default text displaying incorrectly for element links +- Fixed the select toggle where there is multiple Linkit field's on the same layout +- Fixed the default text displaying incorrectly for element links ### Added - -* Added `getLinkAttributes()` to access any addional attributes set by Linkit -* Added `getTargetString()` to access the current target setting `_self` or `_blank` +- Added `getLinkAttributes()` to access any addional attributes set by Linkit +- Added `getTargetString()` to access the current target setting `_self` or `_blank` ## 1.0.5 - 2018-03-31 -* Case fix - thanks Brad! +- Case fix - thanks Brad! ## 1.0.4 - 2018-03-30 -* Updated naming - thanks Brandon! +- Updated naming - thanks Brandon! ## 1.0.3 - 2018-03-27 -* Updated settings page to group link types. -* Enabling link types is now done with lightswitches instead of checkboxes +- Updated settings page to group link types. +- Enabling link types is now done with lightswitches instead of checkboxes ## 1.0.2 - 2018-03-27 -* Updated icon and license. +- Updated icon and license. ## 1.0.0 - 2018-03-27 -* Initial release +- Initial release diff --git a/composer.json b/composer.json index 3100e45..158d256 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "presseddigital/linkit", "description": "One link field to rule them all.", "type": "craft-plugin", - "version": "3.0.0", + "version": "3.0.1", "keywords": [ "craftcms", "link it", diff --git a/src/Linkit.php b/src/Linkit.php index 34fcc15..8813153 100644 --- a/src/Linkit.php +++ b/src/Linkit.php @@ -16,6 +16,7 @@ use craft\services\Elements; use craft\services\Fields; use craft\services\Gql; +use presseddigital\linkit\base\LinkInterface; use presseddigital\linkit\fields\LinkitField; use presseddigital\linkit\services\LinkitService; use presseddigital\linkit\gql\types\LinkType; @@ -124,8 +125,12 @@ public function init() if ($field && $field instanceof LinkitField) { $map = []; foreach ($e->sourceElements as $element) { - $link = $element->$handle; - if ($link && $link->getTypeHandle() === $elementLinkTypeHandle) { + if( + $element->__isset('field:'.$handle) && + ($link = $element->$handle) && + $link instanceof LinkInterface && + $link->getTypeHandle() === $elementLinkTypeHandle + ) { $map[] = [ 'source' => (int)$element->id, 'target' => (int)$link->value ]; } }