private function HierarchyManager::hierarchyGetAllowedParentTypes in Entity Reference Hierarchy 8
Get the allowed parent node types for the given child node type. This method uses configuration management to retrieve the hierarchy settings for allowed parent types based on the child node type.
Parameters
int/null $child_type: The child node type.
Return value
array An array of parent node types allowed for a given child node type.
See also
hierarchyCanBeChild
hierarchyParentOptions
2 calls to HierarchyManager::hierarchyGetAllowedParentTypes()
- HierarchyManager::hierarchyCanBeChild in src/
HierarchyManager.php - HierarchyManager::hierarchyParentOptions in src/
HierarchyManager.php - 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.
File
- src/
HierarchyManager.php, line 227 - Contains \Drupal\entity_hierarchy\HierarchyManager.
Class
- HierarchyManager
- Defines a hierarchy manager.
Namespace
Drupal\entity_hierarchyCode
private function hierarchyGetAllowedParentTypes($child_type = NULL) {
$allowed_children = null;
// Static cache the results because this may be called many times for the same type on the menu overview screen.
static $allowed_types = array();
$config = \Drupal::config('entity_hierarchy.settings');
if (!isset($allowed_types[$child_type])) {
$parent_types = array();
$types = \Drupal\node\Entity\NodeType::loadMultiple();
foreach ($types as $type => $info) {
$allowed_children_unfiltered = $config
->get('nh_allowchild_' . $type);
if ($allowed_children_unfiltered) {
$allowed_children = array_filter($allowed_children_unfiltered);
}
if (empty($child_type) && !empty($allowed_children) || in_array($child_type, (array) $allowed_children, TRUE)) {
$parent_types[] = $type;
}
}
$allowed_types[$child_type] = array_unique($parent_types);
}
return $allowed_types[$child_type];
}