我试图覆盖一个实体引用自动完成表单项,我设法覆盖了表单,并将arg传递给了hook_menu回调。但是,我正在努力根据我在表单框中键入的内容使回调工作。在Entity引用模块中查看,hook_autocomplete_callback中有一些代码可以处理$ string参数并查找匹配项$entity_labels = $handler->getReferencableEntities($tag_last, $instance['widget']['settings']['match_operator']
-诸如此类。
有人可以协助吗?
我的代码:
/**
* Implements hook_form_FORM_ID_alter().
*/
function wl_event_form_event_node_form_alter(&$form, &$form_state, $form_id) {
dpm($form);
// We will get our term id argument from the from build itself.
$node_id = $form['#node']->nid;
// This is the path we will create in hook_menu().
$new_path = "wl_event/autocomplete/{$node_id}";
// Maximum number of descrete values (deltas) that are present.
$max_delta = $form['field_wl_event_acquired_resource']['und']['#max_delta'];
// Hijack the autocomplete callback for each of our values.
for($x=0; $x <= $max_delta; $x++) {
$form['field_wl_event_acquired_resource']['und'][$x]['target_id']['#autocomplete_path']= $new_path;
}
}
/**
* Implements hook_menu().
*/
// can be used to do a lookup on a menu path to return json
// probably entity reference autocomplete does a similar thing
//we want to get all of the resources of the user profiles of
//users who are registered on the event
//
function wl_event_menu() {
$items = array();
$items['wl_event/autocomplete/%'] = array(
'title' => t('project call back'),
'page callback' => 'wl_event_autocomplete_callback',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
function wl_event_autocomplete_callback($arg1, $string = '') {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'resource');
// ->propertyCondition('nid', '1')
$results = $query->execute();
print_r(drupal_json_output($results));
return drupal_json_output($results);
}