We see
in ajax_example_autocomplete.inc the $autocomplete_path = 'examples/ajax_example/node_by_author_autocomplete/' . $author->uid; as below:

  // When the author changes in the author field, we'll change the
  // autocomplete_path to match.
  if (!empty($form_state['values']['author'])) {
    $author = user_load_by_name($form_state['values']['author']);
    if (!empty($author)) {
      $autocomplete_path = 'examples/ajax_example/node_by_author_autocomplete/' . $author->uid;
      $form['node']['#autocomplete_path'] = $autocomplete_path;
      $form['node']['#title'] = t('Choose a node title authored by %author', array('%author' => $author->name));
      $form['node']['#disabled'] = FALSE;
    }
  }

Then the hook menu is:

  $items['examples/ajax_example/node_by_author_autocomplete'] = array(
    'page callback' => 'ajax_example_node_by_author_node_autocomplete_callback',
    'file' => 'ajax_example_autocomplete.inc',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );

Then again , the callback is

function ajax_example_node_by_author_node_autocomplete_callback($author_uid, $string = "") {
  $matches = array();
  if ($author_uid > 0 && trim($string)) {
    $result = db_select('node')
      ->fields('node', array('nid', 'title'))
      ->condition('uid', $author_uid)
      ->condition('title', db_like($string) . '%', 'LIKE')
      ->range(0, 10)
      ->execute();
    foreach ($result as $node) {
      $matches[$node->title . " [$node->nid]"] = check_plain($node->title);
    }
  }

  drupal_json_output($matches);
}

Can some one help us make it clear about when and how author id and string become parameters of the callbackback function?

Thank you in advance.

Comments

waqarit’s picture

When you will start typing in auto-complete field, it will fetch some matching result using callback function. At that time "author_uid" and "string" parameters will be used.

qqboy’s picture

waqarit’s picture

The if condition in first step making all this sense. It check if author uid is not emtpy then pass this to url path because of this is available as a parameter in next function. And the string is a default parameter available in auto-complete function. It holds the value which we type in auto-complete field.

qqboy’s picture

what you said if is this if

if (!empty($form_state['values']['author'])) {
    $author = user_load_by_name($form_state['values']['author']);
    if (!empty($author)) {
      $autocomplete_path = 'examples/ajax_example/node_by_author_autocomplete/' . $author->uid;

Then menu system will put the author id as parameter for page callback function.

Am I right?
The next target is to make this schema clear, but very difficult, since a concept involved -fit-, 'mask', very difficult.

waqarit’s picture

yes, this

if

now what is difficulty?

qqboy’s picture

for example,
if you type node/235
the menu system will search node/%
if not found, menu system will search node
--
'fit of menu' and 'menu mask' are difficulty.
what do you think ?

waqarit’s picture

your example is absolutely right. The "if" condition checks the argument, if argument present then filter search result under this argument. But if there is no argument then show simple result.
I don't think so, there should be any difficulty after clearing this concept.

qqboy’s picture

To me it s difficult, for example

$items['node/%node/delete'] = array(
   //
);

Then

$form_state['redirect'] = array('node/' . $node-> nid . '/delete', array('query'=> $destination));

Now the quetions, is how to match the two, from

'node/' . $node-> nid . '/delete'

to

$items['node/%node/delete'] 

What do you think ? Thank you.

Jaypan’s picture

The % is a wildcard - meaning it will take any value. If a word is appended to it, for example %node, it is still a wildcard, and will accept any value. So:

'node/' . $node->nid . '/delete'

Has a value between node/ and /delete, and therefore will use the path node/%node/delete.

qqboy’s picture