You are here

function _nodehierarchy_widgets_parent_autocomplete_options in Node Hierarchy 7.4

Same name and namespace in other branches
  1. 6.3 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()
  2. 6.2 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()
  3. 7.2 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()

Return a list of menu items that are valid possible parents for the given node.

2 calls to _nodehierarchy_widgets_parent_autocomplete_options()
nodehierarchy_widgets_autocomplete_parent in nodehierarchy_widgets/nodehierarchy_widgets.module
Page callback for autocomplete.
_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 89
Alternative parent selector widgets for Node Hierarchy.

Code

function _nodehierarchy_widgets_parent_autocomplete_options($child_type, $exclude = NULL, $string = NULL) {
  $out = array();

  // Get all the possible parents.
  $types = nodehierarchy_get_allowed_parent_types($child_type);

  // Get the items with menu links.
  $items = $mlids = $tree = array();
  if ($types) {
    $query = db_select('node', 'n')
      ->fields('n', array(
      'nid',
      'type',
      'title',
      'uid',
      'status',
    ))
      ->condition('n.type', $types, 'IN')
      ->condition('n.title', '%' . db_like($string) . '%', 'LIKE');
    if ($exclude) {
      $query
        ->condition('n.nid', (array) $exclude, 'NOT IN');
    }
    $result = $query
      ->execute();
    foreach ($result as $item) {
      if (user_access('create child of any parent') || node_access('update', $item)) {
        $out[$item->nid] = array(
          'title' => $item->title,
          'nid' => $item->nid,
        );
      }
    }
  }
  return $out;
}