public function HierarchyManager::addHierarchyFormElement in Entity Reference Hierarchy 8
Builds the elements of the hierarchy form to be included on the node form.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\node\NodeInterface $node: The node whose form is being viewed.
\Drupal\Core\Session\AccountInterface $account: The account viewing the form.
bool $collapsed: If TRUE, the fieldset starts out collapsed.
Return value
array The form structure, with the hierarchy elements added.
Overrides HierarchyManagerInterface::addHierarchyFormElement
See also
entity_hierarchy_form_node_form_alter
File
- src/
HierarchyManager.php, line 87 - Contains \Drupal\entity_hierarchy\HierarchyManager.
Class
- HierarchyManager
- Defines a hierarchy manager.
Namespace
Drupal\entity_hierarchyCode
public function addHierarchyFormElement(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE) {
$access = $account
->hasPermission('administer hierarchy');
$form['hierarchy'] = array(
'#type' => 'details',
'#title' => t('Page Hierarchy'),
'#group' => 'advanced',
'#open' => !$collapsed,
//empty($form_state['entity_hierarchy_expanded']) ? TRUE : FALSE,
'#weight' => 10,
'#access' => $access,
'#tree' => FALSE,
);
$form['hierarchy']['entity_hierarchy_parents'] = array(
'#tree' => TRUE,
);
foreach ((array) $node->entity_hierarchy_parents as $key => $parent) {
$form['hierarchy']['entity_hierarchy_parents'][$key] = $this
->hierarchyNodeParentFormItems($node, $parent, $key);
// Todo: determine if still needed/functionality
\Drupal::moduleHandler()
->alter('entity_hierarchy_node_parent_form_items', $form['hierarchy']['entity_hierarchy_parents'][$key], $node, $parent);
}
\Drupal::moduleHandler()
->alter('entity_hierarchy_node_parent_form_items_wrapper', $form['hierarchy'], $form_state, $node);
return $form;
}