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.
Hi,
I'm fairly new to Drupal, but yesterday I found and applied a patch that I really needed: http://drupal.org/node/20963
In digging into taxonomy_select_nodes() is struck me as odd that there is a limit of 15 items in the result even when $pager is FALSE. I would think that in that case you would want an unlimited result.
Again, I'm new, so if I'm missing something conceptually, please let me know.
Comment | File | Size | Author |
---|---|---|---|
#38 | taxonomy_select_nodes_limit_35.patch | 3.17 KB | jweowu |
#33 | taxonomy_select_nodes_limit2.patch | 2.89 KB | jweowu |
#34 | taxonomy_select_nodes_limit2.patch | 3.21 KB | jweowu |
#29 | taxonomy_select_nodes_limit.patch | 1.9 KB | jweowu |
#24 | taxonomy_select_nodes_limit.patch | 1.78 KB | jweowu |
Comments
Comment #1
aries CreditAttribution: aries commentedAgreed, I'm in the same situation... There should be a smart solution, but I haven't found it yet. :]
Comment #2
aries CreditAttribution: aries commentedHere's a simple patch which compatbile with the 4.6.3's taxonomy.module. It works for me, compatbile with the older one.
Bests,
Aries
http://aries.mindworks.hu
Comment #3
chx CreditAttribution: chx commentedThe code style is terrible. Otherwise it looks good.
Comment #4
aries CreditAttribution: aries commentedAnother implementation. Goba suggested that I should use an extra parameter to handle the limit. Ok.
Comment #5
aries CreditAttribution: aries commentedSorry, the second patch is identical with the first one. Here comes the good one.
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedthere are other listing pages like home page, tracker, feeds, etc. do they all need to use this limit scheme?
Comment #7
aries CreditAttribution: aries commentedI don't know, but it was important for me when I implemented some custom node lister.
Comment #8
gregglesMarked http://drupal.org/node/31765 as a duplicate of this issue.
Comment #9
magico CreditAttribution: magico commentedComment #10
magico CreditAttribution: magico commentedThis is more a feature than a bug.
Comment #11
cooperaj CreditAttribution: cooperaj commentedI'm moving this to 6.x-dev as (to my understanding) that's where the feature requests should live?
The reason I've come across this is because I need to use the functionality this patch offers. I have created a navigation system for an intranet that allows you to drill down into a vocabulary. Only seeing links to the next level of the hierarchy as well as nodes within that term. The reason I use this function is because I am appending the count i.e. '(2)' of all nodes within a given term and its child hierarchy. For example.
drill down: My Category (4) Another (22)
I was really perplexed as to why my count only ever said a maximum of '(10)' no matter how many nodes were contained within the sub-hierarchy. Turns out it was the limit on feed items! IMHO a completely irrelevant variable.
There needs to be some way to specify an 'all' count so that all nodes within a hierarchy are returned.
Thanks
Adam
P.S.
Comment #12
marcp CreditAttribution: marcp commentedAdd the nodeorder project to the list of projects that would make use of an additional parameter to taxonomy_select_nodes() that limits the number of returned nodes. For now we're either stuck with the 'feed_default_items' setting or copying the entire function.
A good patch should be able to apply 4.7 and 5.x shouldn't it? Does this really have to wait 'til 6.x?
Comment #13
marcp CreditAttribution: marcp commentedAttached is yet another patch that does just about the same thing. This one is backwards compatible, and it is for 4.7.4. If you don't pass in the $count parameter, everything runs just the way it does now. Here's how it works (from the parameter list in the function's comment block):
Any chance we can get this committed to the 4.7 branch? If so, I'd be glad to work on the 5.x patch as well...
Comment #14
marcp CreditAttribution: marcp commentedAttached is the patch re-rolled for HEAD (Drupal 6). Probably doesn't make sense at this point to put the patch in any version prior to 6, but I switched the category to "bug report" from "feature request" because I suspect there are quite a few contributed modules out there that will get bitten by http://drupal.org/node/114774#taxonomy-revisions and whose jobs will be made more difficult because they have cut-and-pasted their own copies of taxonomy_select_nodes(). I apologize in advance for setting this to "bug report"...
Marc
Comment #15
catchThis still applies with a big offset. But probably for drupal 7 now. Moving back to feature as well, the upgrade docs are there for just that purpose.
Comment #16
Robin Monks CreditAttribution: Robin Monks commentedPlease re-roll.
Robin
Comment #17
Chad_Dupuis CreditAttribution: Chad_Dupuis commentedsubscribing as I have to look for this patch every time I do an upgrade or setup a new site.
+1 for finally getting this bug fixed -- this has been asked for over the last three versions of Drupal.
Comment #18
catch#296632: taxonomy_select_nodes() uses 'feed_default_items' system variable when pager is FALSE
#389598: taxonomy_select_nodes() limits results based on "Number of posts on main page" variable.
Were both duplicates.
Comment #19
catchAnother duplicate #21882: Add $pager_alt variable to taxonomy_select_nodes
Comment #20
jweowu CreditAttribution: jweowu commentedAnother attempt at a patch for this issue. Against a fresh checkout of D7 HEAD.
Very definitely needs review -- this is my first encounter with the Drupal 7 DB abstraction, and I don't have a D7 site set up to test with yet.
The $limit argument defaults to NULL, which retains the existing behaviour of using the 'default_nodes_main' variable value.
Negative integer values indicate no limit. I thought about using FALSE for this, but -1 is often used as a substitute for 'unlimited', and it meant one less check to do.
Comment #22
jweowu CreditAttribution: jweowu commentedTrying again using cvs diff.
Comment #23
jweowu CreditAttribution: jweowu commentedRight, I've tested this on paged and unpaged queries in D7. I made a mistake in the comments, though, so am attaching a fixed version.
Comment #24
jweowu CreditAttribution: jweowu commentedAnd again, for yet another stupid comments error...
Comment #25
Anonymous (not verified) CreditAttribution: Anonymous commentedThis patch is continuing to set $limit using the system variable feed_default_items. This doesn't make a lot of sense to me, but I know it's how Drupal does it now.
This function is called by taxonomy_term_page and taxonomy_term_feed. I don't think we have a limit for taxonomy_term_page as a system variable, so I'd just use the one we use for nodes. The limit should be passed in from taxonomy_term_feeds and taxonomy_term_page.
If limit is NULL, what happens? limit should probably default to -1?
Comment #26
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #27
jweowu CreditAttribution: jweowu commentedSure, some other defaults would be better, but new default behaviour would necessitate changes elsewhere in Drupal where this function is called, which is what I explicitly want to avoid.
This issue has been around since Drupal 4.6.1 (at least), with many duplicates raised over the ensuing years, and it has yet to be fixed.
Because of this, I want this patch to have absolutely no effect on any existing code, yet make it possible for people to use this function as an API-based way of obtaining nodes with a given term assigned, which at present they can't.
Hence: $limit defaults to NULL which means the function uses 'feed_default_items' as normal. But module authors can set $limit if they wish to. And despite it being unpleasant to have to pass that $order array in order to pass a $limit, I've left them in that order to ensure the current behaviour is maintained when there is no $limit specified.
I'm changing this back to 'needs review'. Feel free to revert that if you still disagree.
Comment #28
catchAt a minimum, taxonomy_term_page() needs to be changed to explicitly pass the default nodes main variable to this - otherwise we'll be paging based on the feed default, rather than the nodes per page default.
Comment #29
jweowu CreditAttribution: jweowu commentedAh hell. Thank you. I completely messed that patch up by not noticing that paged and unpaged used two completely different variable names for the limit! That explains how I ended up with that mis-match in the header comments, though.
Comment #30
jweowu CreditAttribution: jweowu commentedComment #31
catchAhh, much better. We might want to look at this a bit more later, but this suddenly becomes a much more useful function than before and it's a very small change. Please wait for test bot before commit.
Comment #32
Dries CreditAttribution: Dries commentedI don't like how we have multiple defaults hard-coded in the function. These should be passed in by the caller, IMO.
Comment #33
jweowu CreditAttribution: jweowu commentedI guess that's approval to do this properly, then. Sounds good to me.In core,
taxonomy_select_nodes()
is only called in two places, both within taxonomy.pages.inc:taxonomy_term_feed()
andtaxonomy_term_page()
.There's a bug (maybe two) in the existing
taxonomy_term_feed()
-- it thinks that the first argument is still an array (and I also suspect that the second array item is supposed to be the pager argument). I thinktaxonomy_select_nodes()
should support multi-term arguments for it to be a good API function. Should we try to get that functionality back at the same time as dealing with limits?The multi-term issue aside, for the original problem I would propose that we change the current D7 prototype to:
taxonomy_select_nodes($term, $pager = TRUE, $limit = -1, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC'))
(or would people prefer
$limit = NULL
to indicate no limit?)Comment #34
jweowu CreditAttribution: jweowu commentedActually, I'm not sure why the change was made from passing term ids to passing a term object, from which only the tid is used. Just passing the tid (or tids, if we move back to multiple terms) seems to make more sense. Patch updated accordingly.
Comment #35
catchComment #36
catchNow that there's no default, it looks like $limit could just default to FALSE?
Comment #37
Dries CreditAttribution: Dries commentedI like this patch a lot better. I think FALSE makes more sense than -1.
Comment #38
jweowu CreditAttribution: jweowu commentedChanged to FALSE.
I've taken out the
$limit = (int) $limit;
check, and haven't replaced it with anything to ensure that a non-FALSE $limit argument is a positive integer (or a string representation thereof). You do now end up with a SQL syntax error if the $limit argument is invalid. Should invalid inputs be handled, or is it appropriate to let it fail? I'm not sure what the preference is.Validation when setting the 'default_nodes_main' and 'feed_default_items' variables probably factors into this, and system.admin.inc uses
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30))
for both, so things will generally be fine for the core uses of this function without extra error checking required. I'm happy to add it in, though.Comment #40
jweowu CreditAttribution: jweowu commentedI'm not seeing why that failed testing, when the previous patch was fine. It says one hook menu test failure, but doesn't give more detail than that, so I'm not sure where the supposed failure was. False positive?
Comment #41
catchSending for re-test.
Comment #42
catchPatch looks much better. We don't validate for completely invalid arguments, just let things fail.
Only thing I'd change is
($limit !== FALSE)
which should just beif ($limit)
Comment #43
jweowu CreditAttribution: jweowu commentedThe query is valid when $limit = 0, so we definitely don't want that to return unlimited results in that instance (even if no one should sensibly be requesting that).
Comment #44
catchThat shouldn't hold this up and makes enough sense. I've got a bad feeling we've missed the deadline for API changes. But since the function signature here was changed only 2-3 days ago, this is arguably critical cleanup after the field API conversion - especially since no-one can directly query term_node tables any more, so this function become more important when upgrading. Dries/webchick - please move to D8 if this is considered too late.
Comment #45
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD still. Thanks!
Comment #47
jweowu CreditAttribution: jweowu commentedNow that this is fixed in D7, would a patch for Drupal 6 be considered if it does not change the behaviour of any existing calls to the function? (i.e. the new limit argument is last, optional, and the default value maintains the existing behaviour).
Comment #48
ak CreditAttribution: ak commentedsubscribing, that would be great.
Comment #49
greggles@jweowu, the best way to find out is to provide such a patch. Gabor is sometimes open to changes like that.
Comment #50
OmarQot CreditAttribution: OmarQot commented#38: taxonomy_select_nodes_limit_35.patch queued for re-testing.
Please ignore, re-testing. it was mistake
Comment #51
verta CreditAttribution: verta commentedsubscribing
Comment #53
verta CreditAttribution: verta commented"Ensure the patch applies to the lastest checkotu of the code-base."
?
Comment #54
guictx CreditAttribution: guictx commentedSubscribing
Comment #55
1kenthomas CreditAttribution: 1kenthomas commented//subscribing.
Comment #56
blauerberg CreditAttribution: blauerberg commentedSubscribing
Comment #57
verta CreditAttribution: verta commented#38: taxonomy_select_nodes_limit_35.patch queued for re-testing.
Comment #59
verta CreditAttribution: verta commented#38: taxonomy_select_nodes_limit_35.patch queued for re-testing.
Comment #61
jweowu CreditAttribution: jweowu commentedverta: That's a patch for Drupal 7 (which was committed). There's no point in re-testing it now, because it doesn't apply to Drupal 6.
Comment #62
verta CreditAttribution: verta commentedThanks for clarifying. Unfortunately, we are still using D6. The reason I was following this issue was that we wanted to be able to use the Priorities module. The limit of 15 taxonomy items was a show stopper there.
I come back from time to time to see if this is ever going to be fixed in D6. I don't know how to "roll" a patch, but I can test whether or not a dev release fixes a given issue or not.
Comment #63
sepehr.sadatifar CreditAttribution: sepehr.sadatifar commentedsubscribing
Comment #64
ndrosev CreditAttribution: ndrosev commented#24: taxonomy_select_nodes_limit.patch queued for re-testing.
Comment #65
thedavidmeister CreditAttribution: thedavidmeister commentedThere is nothing to review for D6 here.
My gut feeling is that since this fix requires an API change, and that to make the same change to D6 that happened in D7 would require breaking anything using this function that passes in $order, and that with D8 around the corner D6 is definitely not accepting new functionality at this point, this is probably a "won't fix".