private function HierarchyManager::hierarchyNodeParentFormItems in Entity Reference Hierarchy 8
Build the parent form item for a given parent node object. This function is called iteratively in addHierarchyFormElement method to build a dropdown list of parents. We add a visible title (node title), the hierarchy id (hid), a parent node id (pid), a child weight (cweight), a parent weight (pweight), and a delete flag to each dropdown item.
The dropdown element to select the desired title is added by the method hierarchyGetParentSelector.
Parameters
\Drupal\node\NodeInterface $node: The node being built or being edited
$parent: The parent object
Return value
array The array containg all the important information associated with the given dropdown item.
See also
addHierarchyFormElement
hierarchyGetParentSelector
1 call to HierarchyManager::hierarchyNodeParentFormItems()
- HierarchyManager::addHierarchyFormElement in src/
HierarchyManager.php - Builds the elements of the hierarchy form to be included on the node form.
File
- src/
HierarchyManager.php, line 281 - Contains \Drupal\entity_hierarchy\HierarchyManager.
Class
- HierarchyManager
- Defines a hierarchy manager.
Namespace
Drupal\entity_hierarchyCode
private function hierarchyNodeParentFormItems(NodeInterface $node, $parent) {
// Wrap the item in a div for js purposes
// Todo: change the dropdown selector to an autocomplete if it makes sense.
$item = array(
'#type' => 'fieldset',
'#title' => t('Parent'),
'#tree' => TRUE,
'#prefix' => '<div class="entity_hierarchy-parent">',
'#suffix' => '</div>',
);
// The parent node ID
$pnid = $parent->pnid;
// The node ID of the node being created or edited
$nid = $node
->id();
// If a node can be a child of another add a selector to pick the parent. Otherwise set the parent to 0.
if ($this
->hierarchyCanBeChild($node)) {
$item['pnid'] = $this
->hierarchyGetParentSelector($node
->getType(), empty($pnid) ? null : $pnid, empty($nid) ? null : $nid);
$item['pnid']['#weight'] = -1;
}
else {
$item['pnid'] = array(
'#type' => 'value',
'#value' => 0,
);
}
$item['hid'] = array(
'#type' => 'value',
'#value' => isset($parent->hid) ? $parent->hid : NULL,
);
$item['cweight'] = array(
'#type' => 'value',
'#value' => isset($parent->cweight) ? $parent->cweight : NULL,
);
$item['pweight'] = array(
'#type' => 'value',
'#value' => isset($parent->pweight) ? $parent->pweight : NULL,
);
if (!empty($parent->hid)) {
$item['remove'] = array(
'#type' => 'checkbox',
'#title' => t('Remove this parent'),
'#weight' => 100,
);
}
return $item;
}