function _nodehierarchy_widgets_is_invalid_parent in Node Hierarchy 7.2
Same name and namespace in other branches
- 6.3 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_is_invalid_parent()
- 6.2 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_is_invalid_parent()
- 7.4 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_is_invalid_parent()
Return a list of menu items that are valid possible parents for the given node.
1 call to _nodehierarchy_widgets_is_invalid_parent()
- _nodehierarchy_widgets_autocomplete_parent_validate in nodehierarchy_widgets/
nodehierarchy_widgets.module - Validate a node hierarchy autocomplete in the format 'Tile [nid:xx]' or '[nid:xx]' or 'Title'.
File
- nodehierarchy_widgets/
nodehierarchy_widgets.module, line 120 - Alternative parent selector widgets for Node Hierarchy.
Code
function _nodehierarchy_widgets_is_invalid_parent($parent_nid, $child_nid, $child_type) {
$parent = node_load($parent_nid);
// Check for a valid parent type.
if (!$parent) {
return t('The specified parent cannot be found');
}
// Check for a valid parent type.
$types = nodehierarchy_get_allowed_parent_types($child_type);
if (!in_array($parent->type, $types)) {
return t('%title cannot be a parent of this node because %type is not an allowed parent node type.', array(
'%title' => $parent->title,
'%type' => node_type_get_name($parent->type),
));
}
// Check that the parent is not a child of itself
if ($parent_nid == $child_nid) {
return t('%title cannot be a parent of itself.', array(
'%title' => $parent->title,
));
}
// Check that the parent is not a descendant of the given node.
$ancestors = nodehierarchy_get_node_ancestor_nids($parent_nid);
if (in_array($child_nid, $ancestors)) {
return t('%title cannot be a parent of this node it is a descendant of the node.', array(
'%title' => $parent->title,
));
}
return FALSE;
}