Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Model support for TreeItemSelector control source data #2023

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix CS
  • Loading branch information
mkrecek234 committed Mar 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 17306b94b793f90c1fd6a4a4f61a278d7804288a
6 changes: 4 additions & 2 deletions src/Form/Control/TreeItemSelector.php
Original file line number Diff line number Diff line change
@@ -120,12 +120,14 @@ public function setTreeItems(array $treeItems)
return $this;
}

protected function addNodes(Model $model, $parentId = null)
protected function addNodes(Model $model, $parentId = null): array
{
// return an array of items with parent = $parentId
$result = [];

if ($parentId) { $model->addCondition($this->parentIdField, $parentId); }
if ($parentId) {
$model->addCondition($this->parentIdField, $parentId);
}

foreach ($model as $node) {
if ($node->get($this->parentIdField) === $parentId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this cond?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we have to set a new parentId condition on an unconditioned model, otherwise will have contradictory conditions