Skip to content

Commit 34f8388

Browse files
committed
Merge remote-tracking branch 'origin/craft-5-develop' into craft-5
2 parents add6168 + 088c18f commit 34f8388

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/services/BlockUsageService.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,41 @@ public function getBlockEntries(int $fieldId, int $blockId)
156156
return $ret;
157157
}
158158

159-
public function getEntryTypeEntries(int $entryTypeId)
159+
public function getEntryTypeEntries(int $fieldId, int $entryTypeId)
160160
{
161-
$entryType = Craft::$app->getEntries()->getEntryTypeById($entryTypeId);
161+
$entryType = Craft::$app->getEntries()->getEntryTypeById($entryTypeId) ?? Craft::$app->getEntries()->getEntryTypeById($fieldId);
162162

163-
$entries = Entry::find()->typeId($entryTypeId)->status(null)->collect();
163+
if(!$entryType) {
164+
return [
165+
'block' => [
166+
'name' => '',
167+
],
168+
'entries' => []
169+
];
170+
}
164171

165-
$topLevelEntries = $entries->map(function($entry){
166-
try {
167-
$owner = $entry->getOwner();
172+
$entries = Entry::find()->typeId($entryType->id)->status(null)->collect();
168173

169-
if($owner) {
170-
while($owner->getOwner()) {
171-
$owner = $owner->getOwner();
174+
$topLevelEntries = $entries
175+
->filter(function($entry) use ($fieldId){
176+
return $entry->fieldId === $fieldId;
177+
})
178+
->map(function($entry){
179+
try {
180+
$owner = $entry->getOwner();
181+
if($owner) {
182+
while($owner->getOwner()) {
183+
$owner = $owner->getOwner();
184+
}
172185
}
173-
}
174186

175187

176-
return $owner ?? $entry;
177-
} catch(Exception $e) {
178-
return $entry;
179-
}
180-
})->unique();
188+
return $owner ?? $entry;
189+
} catch(Exception $e) {
190+
return $entry;
191+
}
192+
})
193+
->unique();
181194

182195
$labelHtml = $this->_getEntryTypeLabel($entryType);
183196
return [

src/variables/BlockUsageVariable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function getBlockEntries($fieldId, $blockId): array
3232
return BlockUsage::getInstance()->blockUsageService->getBlockEntries($fieldId, $blockId);
3333
}
3434

35-
public function getEntryTypeEntries($entryId): array
35+
public function getEntryTypeEntries($entryId, $blockId): array
3636
{
37-
return BlockUsage::getInstance()->blockUsageService->getEntryTypeEntries($entryId);
37+
return BlockUsage::getInstance()->blockUsageService->getEntryTypeEntries($entryId, $blockId);
3838
}
3939

4040
public function getEntryTypes($fieldId): array

0 commit comments

Comments
 (0)