Skip to content

Commit

Permalink
Actually check the database for getHasDescendants() / getTotalDescend…
Browse files Browse the repository at this point in the history
…ants()

Fixes #4504
  • Loading branch information
brandonkelly committed Jul 11, 2019
1 parent 688f2ba commit 6d0680e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fixed an error that could occur if a template was accessing the deprecated `locale` property of an element query, but `siteId` wasn’t set to an integer. ([#4531](https://github.com/craftcms/cms/issues/4531))
- Fixed a bug where users without the “Publish live changes” permission for a section weren’t able to create new entries. ([#4528](https://github.com/craftcms/cms/issues/4529))
- Fixed a PHP error that could occur when uploading files to Assets fields on the front-end. ([#4382](https://github.com/craftcms/cms/issues/4382))
- Fixed a bug where elements listed in a Structure view could show descendant toggles even if they had no descendants. ([#4504](https://github.com/craftcms/cms/issues/4504))

## 3.2.0 - 2019-07-09

Expand Down
14 changes: 9 additions & 5 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -1632,19 +1632,23 @@ public function getNextSibling()
*/
public function getHasDescendants(): bool
{
return ($this->lft !== null && $this->rgt !== null && $this->rgt > $this->lft + 1);
$descendants = $this->getDescendants();
if (is_array($descendants)) {
return !empty($descendants);
}
return $descendants->exists();
}

/**
* @inheritdoc
*/
public function getTotalDescendants(): int
{
if ($this->getHasDescendants()) {
return ($this->rgt - $this->lft - 1) / 2;
$descendants = $this->getDescendants();
if (is_array($descendants)) {
return count($descendants);
}

return 0;
return $descendants->count();
}

/**
Expand Down

0 comments on commit 6d0680e

Please sign in to comment.