Currently the autocomplete function that allows users to add nodes to a queue either runs the default db_select to obtain matching nodes or, in cases where a third party module is implementing its own nodequeue, it passes to that module.
This patch adds a drupal_alter so that any third party module can modify nodequeue api autocomplete matches.
Example:
function hook_nodequeue_api_autocomplete_alter(&$matches, $context) {
if ($context['queue']->name == 'my_queue') {
foreach ($matches as $nid => $title) {
$matches[$nid] = str_replace('foo', 'bar', $title);
}
}
}
And of course there are plenty of other uses where adding or removing matches would be useful (e.g. a permissions module could remove matches based on arbitrary parameters)
p.s. - You could run hook_query_alter() to adjust the match results, but the query is only tagged with "node_access" and "i18n_select", but not "nodequeue"... so it's difficult to isolate the query.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | nodequeue-1463552-6.patch | 1.52 KB | alexkb |
| #5 | nodequeue-1463552-5.patch | 1.85 KB | alexkb |
| #2 | 1463552-autocomplete-alter-7.2.patch | 899 bytes | jaydub |
| #1 | 1463552-autocomplete-alter.patch | 899 bytes | jaydub |
| nodequeue_autocomplete_alter-d7.x-2.x.patch | 494 bytes | jyee |
Comments
Comment #1
jaydub commentedI made a change to this patch which I agree can be useful when a full implementation of {$queue->owner}_nodequeue_autocomplete() is not needed.
The alter hook should be able to alter not only the results of the default nodequeue module implementation of {$queue->owner}_nodequeue_autocomplete() but also an actual custom implementation of {$queue->owner}_nodequeue_autocomplete().
Hope that makes sense :)
Note this patch is for 7.3 branch. Not sure if 7.2 or 7.3 is where new development is happening.
Comment #2
jaydub commentedHere is patch for 7.2 branch
Comment #3
rajiv.singh commented#1: 1463552-autocomplete-alter.patch queued for re-testing.
Comment #4
rajiv.singh commented#2: 1463552-autocomplete-alter-7.2.patch queued for re-testing.
Comment #5
alexkb commentedI'm struggling to see how I can customise the autocomplete function for nodequeue created nodequeues. That is, where the queue owner passed to nodequeue_api_autocomplete() is equal to "nodequeue" and so a call to
$queue->owner . "_nodequeue_autocomplete";is pointless.If this were true, shouldn't a drupal_alter exist instead of the
$function($queue, $subqueue, $string, $where, $where_args);so that it doesn't do multiple queries on the database unnecessarily?It's possible this whole nodequeue_api_autocomplete() function needs a rewrite, as there are references to $where and $where_args that aren't initialized.
Attached is a patch for the 2.x branch of nodequeue, to add a hook call above the queries, to let other modules do their own version of the autocomplete function.
Or, perhaps I've misunderstood how to set the queue owner - I had a look around, but couldn't find a solution. Any pointers on this would be greatly appreciated, and obviously if this is the preferred way to do things, then feel free to ignore this patch.
Comment #6
alexkb commentedIgnore the previous patch, it won't work very well because when module_invoke_all() runs as it resets the index of the returned array, which causes issues for autocomplete.
Instead, I've opted for adding an sql tag to the query so that we can simply do a query_alter to the existing query.
Updated patch attached for 7.x-2.x branch.
Comment #7
steven jones commentedGoing to mark this as a duplicate of #2231793: Autocomplete does not pass autocomplete text to hook because the patch there is doing the same thing, but doing it a little better by using the metadata API on the query object.
Let's get some more reviews over there and get this RTBC