Saya mencoba untuk menimpa item formulir autocomplete entitasreference, saya telah berhasil menimpa formulir, dan mendapatkan arg diteruskan ke panggilan balik hook_menu. Namun, saya kesulitan mendapatkan panggilan balik untuk bekerja berdasarkan apa yang saya ketik di kotak formulir. Mencari di modul referensi Entitas ada beberapa kode di hook_autocomplete_callback yang menangani argumen $ string dan mencari kecocokan $entity_labels = $handler->getReferencableEntities($tag_last, $instance['widget']['settings']['match_operator']
- sesuatu seperti itu.
Adakah yang bisa membantu?
Kode saya:
/**
* 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);
}