TreePositionHostTrait
Node position in a tree edit form: a shared {@see TreePosition} component with the grid's move-to modal, so the conversion of the choice into a move exists once.
Host (presenter with a tree form):
use TreePositionHostTrait;+ treePositionConfig() (manager, label, edited node, scope),- in the form
$this->addTreePositionFields($form)next to the hiddenparentId, - in the save
$this->buildTreeMoveMeta(...)instead of a hand-mademeta['moveSubtreeToParentId']and on failure$this->flashTreeMoveFailure($result, $meta), - in the template
{control treePosition}under the parent picker (rendered only for an existing node).
The move runs in the Api afterSave inside the save transaction
(TreeTrait::applyMetaSubtreeMove()); without a choice
(keep the current place) a parent change appends the node as the last child.
Table of Contents
Properties
Methods
- addTreePositionFields() : void
- Position fields for the form (default: keep the current place).
- buildTreeMoveMeta() : array<string, mixed>|null
- Move meta for `save()` of an existing node; `null` means an invalid choice (the flash is already set, the caller just returns `false`). `[]` means nothing moves.
- createComponentTreePosition() : TreePosition
- flashTreeMoveFailure() : bool
- Failure message for a save with a tree-specific reason (stale snapshot, lock, invalid target); only when the save really carried a move. `false` means the caller sets its own generic message.
- treePositionConfig() : TreePositionConfig
- Position configuration for the edited node; pure, also called on the AJAX signal `siblings!`.
Properties
$treePositionFactory
public
TreePositionFactory
$treePositionFactory
Attributes
- #[Inject]
Methods
addTreePositionFields()
Position fields for the form (default: keep the current place).
protected
addTreePositionFields(Container $form) : void
Parameters
- $form : Container
buildTreeMoveMeta()
Move meta for `save()` of an existing node; `null` means an invalid choice (the flash is already set, the caller just returns `false`). `[]` means nothing moves.
protected
buildTreeMoveMeta(ArrayHash<string|int, mixed> $values, int|null $nodeId, int|null $originalParentId, int|null $newParentId) : array<string, mixed>|null
Parameters
- $values : ArrayHash<string|int, mixed>
- $nodeId : int|null
- $originalParentId : int|null
- $newParentId : int|null
Return values
array<string, mixed>|nullcreateComponentTreePosition()
protected
createComponentTreePosition() : TreePosition
Return values
TreePositionflashTreeMoveFailure()
Failure message for a save with a tree-specific reason (stale snapshot, lock, invalid target); only when the save really carried a move. `false` means the caller sets its own generic message.
protected
flashTreeMoveFailure(Result $result, array<string, mixed> $meta) : bool
Parameters
- $result : Result
- $meta : array<string, mixed>
-
meta the save was run with
Return values
booltreePositionConfig()
Position configuration for the edited node; pure, also called on the AJAX signal `siblings!`.
protected
abstract treePositionConfig() : TreePositionConfig