File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -181,9 +181,17 @@ public function __toString()
181181
182182 public function assignPositions (): void
183183 {
184- $ rootItems = $ this ->getItemsByParent ();
184+ /** @var MenuItem[] $childrens */
185+ $ childrens = $ this ->items ->filter (function (MenuItem $ item ) {
186+ return null === $ item ->getParent ();
187+ })->getValues ();
188+
189+ usort ($ childrens , function (MenuItem $ a , MenuItem $ b ) {
190+ return $ a ->getPosition () <=> $ b ->getPosition ();
191+ });
192+
185193 $ position = 0 ;
186- foreach ($ rootItems as $ item ) {
194+ foreach ($ childrens as $ item ) {
187195 $ item ->setPosition ($ position );
188196 $ item ->assignPositions ();
189197 ++$ position ;
Original file line number Diff line number Diff line change @@ -315,7 +315,13 @@ public function update(array $properties): void
315315
316316 public function assignPositions (): void
317317 {
318- $ childrens = $ this ->getChildrens ();
318+ /** @var MenuItem[] $childrens */
319+ $ childrens = $ this ->getChildrens ()->getValues ();
320+
321+ usort ($ childrens , function (MenuItem $ a , MenuItem $ b ) {
322+ return $ a ->getPosition () <=> $ b ->getPosition ();
323+ });
324+
319325 $ position = 0 ;
320326 foreach ($ childrens as $ child ) {
321327 $ child ->setPosition ($ position );
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ public function fromHash($hash): ?MenuItem
8888 $ currentParent = $ menuItem ->getParent ();
8989 if ($ currentParent && (!isset ($ hash ['parentId ' ]) || null === $ hash ['parentId ' ])) {
9090 $ currentParent ->removeChildren ($ menuItem );
91- } elseif ($ hash ['parentId ' ] && (!$ currentParent || $ currentParent ->getId () !== $ hash ['parentId ' ])) {
91+ } elseif ($ hash ['parentId ' ] && (!$ currentParent || $ currentParent ->getId () !== ( int ) $ hash ['parentId ' ])) {
9292 $ parent = $ menuItemRepo ->find ($ hash ['parentId ' ]);
9393 if ($ parent ) {
9494 $ parent ->addChildren ($ menuItem );
You can’t perform that action at this time.
0 commit comments