2

The CKEditor Link User module has essentially the functionality I need, but it requires editors to know users by their 'name' field in the users table. I wanted to extend the query to join with the field_data_field_full_name table so that editors could type full names to populate suggestions. The original code:

<?php

/**
 * Implementation of hook_ckeditor_link_TYPE_autocomplete().
 */
function ckeditor_link_user_ckeditor_link_user_autocomplete($string) {
  $matches = array();

  $result = db_select('users')
    ->fields('users', array('uid', 'name'))
    ->condition('name', '%'. db_like($string) .'%', 'LIKE')
    ->range(0, 10)
    // ->addTag('user_access'); // Make a proper access hook
    ->execute();

  foreach ($result as $user) {
    $matches['user/'. $user->uid] = t('User: @name', array('@name' => $user->name));
  }

  return $matches;
}

...

My attempt (edited after SO thoughtfully pointed me here):

<?php

/**
 * Implementation of hook_ckeditor_link_TYPE_autocomplete().
 */
function ckeditor_link_user_ckeditor_link_user_autocomplete($string) {
  $matches = array();

  $result = db_select('users', 'u')
  $result->join('field_data_field_full_name', 'ft', 'ft.entity_id = u.uid')
    ->fields('u', array('uid'))
    ->fields('ft', array('field_full_name_value'))
    ->condition('field_full_name_value', '%'. db_like($string) .'%', 'LIKE')
    ->range(0, 10)
    // ->addTag('user_access'); // Make a proper access hook
    ->execute();

  foreach ($result as $user) {
    $matches['user/'. $user->uid] = t('User: @name', array('@name' => $user->field_full_name_value));
  }

  return $matches;
}

...

In the CKEditor Link pop-up, I get a "An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /ckeditor_link/autocomplete StatusText: Internal Server Error..." Nothing is showing up in the error log. I have set Devel to show SQL queries, but I don't see the Ajax query from autocomplete anywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.