You are here

private function HierarchyManager::hierarchyParentOptions in Entity Reference Hierarchy 8

Return a list of valid possible hierarchy parents for the given child node type. This list is passed back to hierarchyGetParentSelector so it can be displayed as a dropdown selection list.

The list is built with the following steps: 1) Get all allowed parent node types for all allowed node types using hierarchyGetAllowedParentTypes 2) Get allowed parent node types for a given child node type using hierarchyGetAllowedParentTypes 3) Build a tree of all possible parent nodes using hierarchyBuildTree and HierarchyOutlineStorage::hierarchyNodesByType 4) Remove or disable parent titles that can't be parents using hierarchyTreeDisableTypes 5) Remove items which the user does not have permission to access using hierarchyTreeDisableNoAccess 6) Remove the option to set a child as its own parent using hierarchyTreeRemoveNid 7) Convert the tree to a flattened list (with depth) using hierarchyFlattenTree

Parameters

string $child_type: The node type of the child used to find valid potential parents

int/null $exclude: Node ID of the parent that should be excluded from the list.

Return value

array The list of valid parents for a given node type.

See also

hierarchyGetParentSelector

hierarchyGetAllowedParentTypes

HierarchyOutlineStorage::hierarchyNodesByType

hierarchyBuildTree

hierarchyTreeDisableTypes

hierarchyTreeDisableNoAccess

hierarchyTreeRemoveNid

hierarchyFlattenTree

1 call to HierarchyManager::hierarchyParentOptions()
HierarchyManager::hierarchyGetParentSelector in src/HierarchyManager.php
Build a list of parent tiles to be displayed as part of a dropdown selector in hierarchyNodeParentFormItems. First we grab a list of allowed parents using the hierarchyParentOptions method. Then we format each title by iteratively calling…

File

src/HierarchyManager.php, line 431
Contains \Drupal\entity_hierarchy\HierarchyManager.

Class

HierarchyManager
Defines a hierarchy manager.

Namespace

Drupal\entity_hierarchy

Code

private function hierarchyParentOptions($child_type, $exclude = NULL) {
  static $options = array();

  // If these options have already been generated, then return that saved version.
  if (isset($options[$child_type][$exclude])) {
    return $options[$child_type][$exclude];
  }
  $types = $this
    ->hierarchyGetAllowedParentTypes();
  $parent_types = $this
    ->hierarchyGetAllowedParentTypes($child_type);
  $parent_tree = $this->hierarchyOutlineStorage
    ->hierarchyNodesByType($types);
  $parent_tree = $this
    ->hierarchyBuildTree($parent_tree);
  $parent_tree = $this
    ->hierarchyTreeDisableTypes($parent_tree, $parent_types);

  //    $parent_tree = $this->hierarchyTreeDisableNoAccess($parent_tree);
  $out = $this
    ->hierarchyTreeRemoveNid($parent_tree, $exclude);
  $out = $this
    ->hierarchyFlattenTree($out);

  // Apply static caching to prevent these options being built more than once.
  $options[$child_type][$exclude] = $out;
  return $out;
}