You are here

function _i18n_node_references in Internationalization 7

Same name and namespace in other branches
  1. 6 i18n.pages.inc \_i18n_node_references()

Find node title matches.

Parameters

$string: String to match against node title

$match: Match mode: 'contains', 'equals', 'starts_with'

$params: Other query arguments: type, language or numeric ones

2 calls to _i18n_node_references()
i18n_node_autocomplete in i18n_node/i18n_node.pages.inc
Node title autocomplete callback
i18n_node_autocomplete2nid in i18n_node/i18n_node.pages.inc
Reverse mapping from node title to nid

File

i18n_node/i18n_node.pages.inc, line 300
User page callbacks for the translation module.

Code

function _i18n_node_references($string, $match = 'contains', $params = array(), $limit = 10) {
  $query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
    'title',
    'type',
  ))
    ->orderBy('n.title')
    ->orderBy('n.type')
    ->range(0, $limit);
  foreach ($params as $key => $value) {
    $query
      ->condition($key, $value);
  }
  switch ($match) {
    case 'equals':
      $query
        ->condition('n.title', $string);
      break;
    case 'starts_with':
      $query
        ->condition('n.title', $string . '%', 'LIKE');
      break;
    case 'contains':
    default:
      $query
        ->condition('n.title', '%' . $string . '%', 'LIKE');
      break;
  }

  // Disable and reenable i18n selection mode so no language conditions are inserted
  i18n_select(false);
  $references = array();
  foreach ($query
    ->execute() as $node) {
    $references[$node->nid] = array(
      'title' => $node->title,
      'rendered' => check_plain($node->title),
    );
  }
  i18n_select(true);
  return $references;
}