CoolCMS API

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):

  1. use TreePositionHostTrait; + treePositionConfig() (manager, label, edited node, scope),
  2. in the form $this->addTreePositionFields($form) next to the hidden parentId,
  3. in the save $this->buildTreeMoveMeta(...) instead of a hand-made meta['moveSubtreeToParentId'] and on failure $this->flashTreeMoveFailure($result, $meta),
  4. 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

$treePositionFactory  : TreePositionFactory

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

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>|null

flashTreeMoveFailure()

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
bool
On this page

Search results