Add targetElementRecord
to before/after move element in structure function and events
#13409
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.
I have a use case where my element needs validation rules when moving it within a structure. See verbb/navigation#359 where I want to enforce user-defined rules on how many nodes for a particular level there can be.
Fortunately, I can use the
Element::beforeMoveInStructure()
function (or theElement::EVENT_BEFORE_MOVE_IN_STRUCTURE
event if I wanted) to trigger validation withelement->validate()
. However, one glaring issue is that I cannot get the to-be-moved element information from the function or event, because it's not passed to it.For example, if I want validation rules to check if something can be placed at
level
2 if something is currently at level 1, there's no way for me to know what the new level will be, until after the fact. I only know about thelevel
of it currently.This information can be grabbed from
$targetElementRecord
.Happy to revise this, or let me know if I've gone about this the wrong way.