Skip to content

Commit

Permalink
Merge pull request #1355 from craftcms/bugfix/1354-relation-field-lim…
Browse files Browse the repository at this point in the history
…it-adjustment

use maxRelations, not limit for the relational fields
  • Loading branch information
angrybrad authored Jul 25, 2023
2 parents 5b7ccb2 + 00ad427 commit 6cb8d6d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/fields/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function parseField(): mixed

$settings = Hash::get($this->field, 'settings');
$folders = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$upload = Hash::get($this->fieldInfo, 'options.upload');
Expand Down
2 changes: 1 addition & 1 deletion src/fields/CalendarEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function parseField(): mixed
}

$sources = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$match = Hash::get($this->fieldInfo, 'options.match', 'title');
Expand Down
14 changes: 10 additions & 4 deletions src/fields/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ public function parseField(): mixed
}

$source = Hash::get($this->field, 'settings.source');
$branchLimit = Hash::get($this->field, 'settings.branchLimit');
$maintainHierarchy = Hash::get($this->field, 'settings.maintainHierarchy');
if ($maintainHierarchy) {
$limit = Hash::get($this->field, 'settings.branchLimit');
} else {
$limit = Hash::get($this->field, 'settings.maxRelations');
}

$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$create = Hash::get($this->fieldInfo, 'options.create');
Expand Down Expand Up @@ -135,7 +141,7 @@ public function parseField(): mixed

$criteria['status'] = null;
$criteria['groupId'] = $groupId;
$criteria['limit'] = $branchLimit;
$criteria['limit'] = $limit;
$criteria['where'] = ['=', $columnName, $dataValue];

Craft::configure($query, $criteria);
Expand All @@ -157,8 +163,8 @@ public function parseField(): mixed
}

// Check for field limit - only return the specified amount
if ($foundElements && $branchLimit) {
$foundElements = array_chunk($foundElements, $branchLimit)[0];
if ($foundElements && $limit) {
$foundElements = array_chunk($foundElements, $limit)[0];
}

// Check for any sub-fields for the element
Expand Down
2 changes: 1 addition & 1 deletion src/fields/CommerceProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function parseField(): mixed
}

$sources = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$node = Hash::get($this->fieldInfo, 'node');
Expand Down
2 changes: 1 addition & 1 deletion src/fields/CommerceVariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function parseField(): mixed
}

$sources = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$node = Hash::get($this->fieldInfo, 'node');
Expand Down
2 changes: 1 addition & 1 deletion src/fields/DigitalProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function parseField(): mixed
}

$sources = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$node = Hash::get($this->fieldInfo, 'node');
Expand Down
2 changes: 1 addition & 1 deletion src/fields/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function parseField(): mixed
}

$sources = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$targetSiteId = Hash::get($this->field, 'settings.targetSiteId');
$feedSiteId = Hash::get($this->feed, 'siteId');
$create = Hash::get($this->fieldInfo, 'options.create');
Expand Down
2 changes: 1 addition & 1 deletion src/fields/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function parseField(): mixed
}

$sources = Hash::get($this->field, 'settings.sources');
$limit = Hash::get($this->field, 'settings.limit');
$limit = Hash::get($this->field, 'settings.maxRelations');
$match = Hash::get($this->fieldInfo, 'options.match', 'email');
$create = Hash::get($this->fieldInfo, 'options.create');
$fields = Hash::get($this->fieldInfo, 'fields');
Expand Down

0 comments on commit 6cb8d6d

Please sign in to comment.