public function EntityReferenceHierarchy::groupSiblingsByWeight in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldType/EntityReferenceHierarchy.php \Drupal\entity_hierarchy\Plugin\Field\FieldType\EntityReferenceHierarchy::groupSiblingsByWeight()
Group siblings by weight.
Parameters
\SplObjectStorage $siblingEntities: Sibling entities keyed by nested set nodes.
string $fieldName: Field name to detect weight from.
Return value
array Array of nested set nodes grouped by weight.
1 call to EntityReferenceHierarchy::groupSiblingsByWeight()
- EntityReferenceHierarchy::postSave in src/
Plugin/ Field/ FieldType/ EntityReferenceHierarchy.php - Defines custom post-save behavior for field values.
File
- src/
Plugin/ Field/ FieldType/ EntityReferenceHierarchy.php, line 301
Class
- EntityReferenceHierarchy
- Plugin implementation of the 'entity_reference_hierarchy' field type.
Namespace
Drupal\entity_hierarchy\Plugin\Field\FieldTypeCode
public function groupSiblingsByWeight(\SplObjectStorage $siblingEntities, $fieldName) {
$weightMap = [];
foreach ($siblingEntities as $node) {
if (!$siblingEntities
->offsetExists($node)) {
continue;
}
$weightMap[$siblingEntities
->offsetGet($node)][] = $node;
}
ksort($weightMap);
return $weightMap;
}