class InsertPosition in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 src/Storage/InsertPosition.php \Drupal\entity_hierarchy\Storage\InsertPosition
Defines a value object for an insert position.
Hierarchy
- class \Drupal\entity_hierarchy\Storage\InsertPosition
Expanded class hierarchy of InsertPosition
1 file declares its use of InsertPosition
- EntityReferenceHierarchy.php in src/
Plugin/ Field/ FieldType/ EntityReferenceHierarchy.php
File
- src/
Storage/ InsertPosition.php, line 10
Namespace
Drupal\entity_hierarchy\StorageView source
class InsertPosition {
const ACTION_ADD_NODE = 'addNode';
const DIRECTION_BEFORE = 'Before';
const DIRECTION_AFTER = 'After';
const DIRECTION_BELOW = 'Below';
const ACTION_MOVE_SUB_TREE = 'moveSubTree';
/**
* Direction to insert, one of the DIRECTION_ constants.
*
* @var string
*/
protected $direction;
/**
* Node to insert before or after.
*
* @var \PNX\NestedSet\Node
*/
protected $reference;
/**
* TRUE to insert, FALSE to move.
*
* @var bool
*/
protected $insert;
/**
* Constructs a new InsertPosition object.
*
* @param \PNX\NestedSet\Node $reference
* Node to insert before or after.
* @param bool $insert
* TRUE if inserting rather than moving.
* @param string $direction
* Direction constants - one of Before/After/Below.
*/
public function __construct(Node $reference, $insert = TRUE, $direction = self::DIRECTION_BEFORE) {
$this->reference = $reference;
$this->direction = $direction;
$this->insert = $insert;
}
/**
* Perform the insert.
*
* @param \Drupal\entity_hierarchy\Storage\NestedSetStorage $storage
* Storage.
* @param \PNX\NestedSet\Node|\PNX\NestedSet\NodeKey $node
* Node to create or insert.
*
* @return \PNX\NestedSet\Node
* Inserted node.
*/
public function performInsert(NestedSetStorage $storage, $node) {
$command = [
'action' => self::ACTION_ADD_NODE,
'direction' => $this->direction,
];
if (!$this->insert) {
$command['action'] = self::ACTION_MOVE_SUB_TREE;
}
$method = implode('', $command);
return call_user_func_array([
$storage,
$method,
], [
$this->reference,
$node,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InsertPosition:: |
protected | property | Direction to insert, one of the DIRECTION_ constants. | |
InsertPosition:: |
protected | property | TRUE to insert, FALSE to move. | |
InsertPosition:: |
protected | property | Node to insert before or after. | |
InsertPosition:: |
constant | |||
InsertPosition:: |
constant | |||
InsertPosition:: |
constant | |||
InsertPosition:: |
constant | |||
InsertPosition:: |
constant | |||
InsertPosition:: |
public | function | Perform the insert. | |
InsertPosition:: |
public | function | Constructs a new InsertPosition object. |