Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By qqboy on
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
When you will start typing in
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.
You are right. How did you
You are right. How did you know it?Thanks.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
The if condition in first
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.
what you said if is this if
what you said if is this if
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.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
yes, thisif
yes, this
now what is difficulty?
for example,
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 ?
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
your example is absolutely
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.
To me it s difficult, for
To me it s difficult, for example
Then
Now the quetions, is how to match the two, from
to
What do you think ? Thank you.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
The % is a wildcard - meaning
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:
Has a value between
node/
and/delete
, and therefore will use the pathnode/%node/delete
.wow thanks a lot. you are
wow thanks a lot. you are great.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js