Skip to content

Commit

Permalink
Ensure $element->descendants is an array before flattening it
Browse files Browse the repository at this point in the history
  • Loading branch information
rungta committed Sep 12, 2023
1 parent 591abbf commit 4c9fd0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Release notes for the Router Craft CMS plugin.



## Unreleased

### Fixed
- Improved compatibility of `relatedTo` elements' descendants on older versions of Craft and PHP.



## 1.4.1 - 2023-09-06

### Added
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ public function actionIndex(string $template, array $variables = [], array $filt
if ($includeDescendants) {
$relatedTo['element'] = array_filter(array_merge(
$relatedTo['element'],
...array_column($relatedTo['element'], 'descendants')
...array_map(function ($element) {
return is_array($element->descendants)
? $element->descendants
: $element->descendants->ids();
}, $relatedTo['element'])
));
}

Expand Down

0 comments on commit 4c9fd0f

Please sign in to comment.