You are here

public function DefaultController::ccl_node_autocomplete in Custom Contextual Links 8

1 string reference to 'DefaultController::ccl_node_autocomplete'
ccl.routing.yml in ./ccl.routing.yml
ccl.routing.yml

File

src/Controller/DefaultController.php, line 110
Contains \Drupal\ccl\Controller\DefaultController.

Class

DefaultController
Default controller for the ccl module.

Namespace

Drupal\ccl\Controller

Code

public function ccl_node_autocomplete($string = '') {
  $matches = [];
  if ($string) {
    $result = db_select('node', 'n')
      ->fields('n', [
      'title',
      'nid',
    ])
      ->condition('title', db_like($string) . '%', 'LIKE')
      ->range(0, 10)
      ->execute();
    foreach ($result as $node) {
      $matches[\Drupal\Component\Utility\Html::escape($node->title) . ' [nid:' . $node->nid . ']'] = \Drupal\Component\Utility\Html::escape($node->title);
    }
  }
  drupal_json_output($matches);
}