Shapes : Add moveShape(), and say how shapes stack - #1002
Merged
Conversation
dkulyk
force-pushed
the
feat/move-shape
branch
2 times, most recently
from
September 8, 2026 19:06
ca0cfc9 to
86bd567
Compare
Progi1984
reviewed
Sep 9, 2026
| * | ||
| * @return static | ||
| */ | ||
| public function moveShape(AbstractShape $shape, int $index) |
Member
There was a problem hiding this comment.
Suggested change
| public function moveShape(AbstractShape $shape, int $index) | |
| public function moveShape(AbstractShape $shape, int $index): self |
Progi1984
reviewed
Sep 9, 2026
Progi1984
left a comment
Member
There was a problem hiding this comment.
Small feedback (and rebase if needed)
The collection of a container is written in order and stacks in that order -- the first shape is at the back -- and there was no way to change that order but to rebuild the array and hand it to `setShapeCollection()`, which is what the reporter of PHPOffice#866 does today. Remove-and-re-add is not a substitute: `unsetShape()` is a bare `unset()`, so it leaves a hole in the keys. `moveShape(AbstractShape $shape, int $index): self` is `moveSlide()` one level down, on the `ShapeCollection` trait, so a slide, a slide layout, a slide master, a group and the note of a slide all get it. The keys are reindexed first, because a hole makes a key say something other than the place the shape sits in. The usage page said nothing about stacking order at all; it now does.
dkulyk
force-pushed
the
feat/move-shape
branch
from
September 9, 2026 07:32
86bd567 to
ef19b39
Compare
Progi1984
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The shapes of a container are written in the order the collection holds them, and that order is the stacking order -- the first shape is at the back, the last is in front. Nothing could change that order but rebuilding the array and handing it back through
setShapeCollection(), which is what the reporter does today:Remove-and-re-add is not a substitute either:
unsetShape()is a bareunset(), so it leaves a hole in the keys andaddShape()'s[] =then appends atmax + 1.moveShape(AbstractShape $shape, int $index)ismoveSlide()(#966) one level down, with the same two guards and the samearray_splicein one step. It lives on theShapeCollectiontrait rather than onAbstractSlide, so a slide, a slide layout, a slide master, aGroupand the note of a slide all get it at once.The collection is reindexed before the search, because after
unsetShape()a key no longer says the place a shape sits in andarray_splice()counts places, not keys.Fixes #866
Checklist:
composer run-script check --timeout=0and no errors were reported