I've been fighting with this for a couple of hours and haven't been able to make any headway.
I am attempting to display a list of taxonomy terms with associated node counts. I'm using the filter option "Summary, sorted ascending", which sort the terms alphabetically by name. The resulting ORDER BY query clause is
ORDER BY term_data_name ASC
I need to sort by term weight and have defined the sort criteria as "Taxonomy: Weight asc", but this appears to be ignored. Is there a way to override/replace the default clause? For example
ORDER BY term_data.weight ASC
It's been a late night (worked through the night actually) and I apologize in advance if the solution is staring me in the face.
Comment | File | Size | Author |
---|---|---|---|
#56 | views-sort_by_term_weight_with_summary_sorted-417312-56.patch | 1.18 KB | Andrew Answer |
| |||
#6 | views_handler_argument.inc_.patch | 3.37 KB | thePanz |
Comments
Comment #1
thePanz CreditAttribution: thePanz commentedSubscribe
Comment #2
johnhanley CreditAttribution: johnhanley commentedI was never able to get this working. The term weights are ignored when sorting. I'm changing this from a support request to a bug report.
Comment #3
thePanz CreditAttribution: thePanz commentedI edited Views to support "Summary, sorted as View".. I've got some warning on multiple view-sorting, but with only "Weight" it's working fine.
I'll post a patch, but I don't know if this will be merged with Views :/
Comment #4
dawehnerpost the patch, and then the patch will be reviewed,
its the normal way for every code of drupal
needs work, because there is missing code ;)
Comment #5
thePanz CreditAttribution: thePanz commented@dreine: I know, I know... I submitted other patches before as you can see from my profile :)
I said that because I feel that my patch is a "just works" hackish edit to Views :) I'll post it tomorrow :-)
Regards
Comment #6
thePanz CreditAttribution: thePanz commentedHere is my patch (hum... my "try to be a-" patch)..
It's working, but is FAR away to be THE solution for this issue.
Some tips:
- this patch isn't no more related to "taxonomy-data" Component
- this patch appears under "Arguments -> Summary, Sort as View" (like "Summary, sort asc/desc")
- this patch incorporates also (partial) #424460: Configurable Argument Breadcrumb code
and last but not the least:
- this patch *really* needs work (and a better Views2 understanding than what I have)
Regards
Comment #7
webchickI had the same problem (wanted to sort a taxonomy summary listing by weight, not by alphabetical).
The proposed solution here is interesting, because it would work for this use case as well as pretty much any others. I'm not adept enough at Views 2 to really suggest improvements, however.
Comment #8
iandickson CreditAttribution: iandickson commentedI'm no coder, but am trying to create a Timeline view - nodes in right order on timeline - that can cope with WHEN vocab that includes terms like 1066, 1939, World War Two.
I figured that VIEWS2 sort by taxonomy weight (so WW2 is given a weight of 1939....) would do the trick, but it doesn't seem to work, and I don't think I've missed anything obvious (my whole site is now Views 2 driven so I've built a lot of them recently, though I still don't get arguments so can't play witgh that patch!).
UPDATE
IDIOT ME - weights run from -127 to 128 with higher/lower resetting accordingly. So year based ones fell over. Obviously an underlying binary thing going on. Works now.
Comment #9
awolfey CreditAttribution: awolfey commentedThanks, thePanz! This works for me.
Comment #10
azoho CreditAttribution: azoho commentedJust starting to get the hang of views.
Assuming I have got the original question right, but you should be able to achieve a view of taxonomies sorted by their weight by creating a view of type 'taxonomy' rather than 'node' (it's the first set of options when you create a new view). Then set the filter to your vocab or tags, and sort criteria by taxonomy weight. Under the fields, you would set a 'taxonomy term' field to link to the taxonomy term page. Unless you are specifically needing the Summary argument action?
Comment #11
awolfey CreditAttribution: awolfey commented@areaten, yes this is really about sorting the summary provided by an argument.
This works for me.
Anything I can do to help get this committed?
Comment #12
Mikeq CreditAttribution: Mikeq commentedI came across a similar sorting override problem trying to generate tag clouds with random content using view cloud module.
Stealing the implementation of a new argument summary sort option from thePanz above (and many thanks for that - it really helped sorting out how to solve my problem), and not calling the summary sort function, (and the immediately following code that disables the view sort) when this option is enabled, had exactly the desired effect.
More details here: http://drupal.org/node/505692#comment-2706360
Thanks again!
Comment #13
dawehnerThis definitive needs more work, because there is code commented out. I don't think this should be left in.
Comment #14
Mikeq CreditAttribution: Mikeq commentedSorry - I should have been clearer about what I was posting.
The code extract in the linked comment (http://drupal.org/node/505692#comment-2706360) has only additions to the Views 6.x-2.8 views_handler_argument.inc, and is not a modification of the patch posted here earlier by thePanz (which does contain commented out code).
The intention was to provide an option where the argument summary sort is devolved to the overall views sort, and I think that this is what the proposed changes do without interfering with other argument summary options.
I am rather new to this game, and also not a developer, so I apologise if this is not an appropriate way of publicising a solution to a particular problem I encountered. I cross-posted here as the thread seems to address a general case for which I had a particular "hack".
Any pointers on how I might do this better in future will be gratefully received!
Comment #15
marcushenningsen CreditAttribution: marcushenningsen commentedThe solution sounds good, but the patch doesn't apply to the latest version of views. I applied the patch manually, and it seems to work.
Marcus
Comment #16
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm trying to apply the patch to views 2.10 with no luck so far. it doesn't work it shows an sql error.
Can you please help?
This sort as view is much needed and it seems I won't find a solution without this patch.
Comment #17
Anonymous (not verified) CreditAttribution: Anonymous commentedtweaking views 2.10 the below makes it work for me but can we get the term_data.weight from a variable? I just can't get the term_data.weight!! please advice in order to add it to the patch.
the change i did based on the patch at #6 was this
function summary_sort($order) {
if ($order == 'asview') {
$this->query->add_orderby(NULL, NULL, '$order', 'term_data.weight');
}
else {
$this->query->add_orderby(NULL, NULL, $order, $this->name_alias);
}
}
Comment #18
TravisCarden CreditAttribution: TravisCarden commentedsubscribing!
Comment #19
drupaljack CreditAttribution: drupaljack commentedsubscribe
Comment #20
hanoiiI haven't really gone into the depth of the patches or anything, just laying out how I think I might work this out, might try to submit a patch.
When selecting any of the following:
* Summary, sorted ascending
* Summary, sorted descending
I would display another two radios (dependent on the previous)
* Sort alphabetically
* Sort by weight
And change the logic to sort accordingly.
I also wonder if this can be made without patching views.
Comment #21
hanoiiAnd I guess this applies to the latest version really
Comment #22
hanoiiActually took a deeper look at this it really proved to be more difficult than I thought.
I think the idea of the patch here is good, although I am not sure it will be flexible enough for any case. For instance I want to build the summary by weight regardless of the view sort criteria.
The way I see it has to be done, although I might not be able to do it at the moment, is to create a special argument handler for taxonomy name, add there additional options for sorting by weight and then build proper code (overriding the proper summary_ functions or creating a new default_summary alltogether).
I see if I can get this through, but not that familiar to every API calls on each of these. Basically, I wonder how to add programmatically the weight on the summary query.
Comment #23
hanoiiI am marking this one as needs review only because I truly like some review on it, if at all possible by Views devs.
I kind of already know this is a work in progress patch but if this might get accepted I might spend a bit more time on it to follow it through into the code.
Of course, proper reviewing and suggestions on how to make it properly for acceptance is very much welcome.
EDIT: Remember to clear the views cache before trying out the patch
A few comments on this patch:
* UI side
- Once summary, sort ascending or summary sort descending is selected, another set of radios will appear allowing you to select between name and weight.
* Coding side
- It will only work for taxonomy term arguments (this is the main thing to fix probably for accepting it, and in which I have doubts in how to structure it properly without repeating too much code).
- It replaces the default views_handler_argument_string for a new argument handler (and argument handler file): views_handler_argument_term_name.inc
- If name was selected (default) in the UI, the normal name (string handling) will occur. If weight is selected, weight is added to the summary query and sorted by that term.
- If I used the Views API properly was only by intuition and luck :)
After the usual coding review of this particular patch, then it comes the task to propagate it to the other taxonomy handlers, which are quite a few, some with custom taxonomy handlers and others with default, such as tid which uses numeric argument handler, so I wonder how to make this work for all?
a.=
Comment #24
nallasivamkn CreditAttribution: nallasivamkn commentedhow do i insert the patch file in views?
Comment #25
TravisCarden CreditAttribution: TravisCarden commented@nallasivamkn: See the handbook page on Applying patches. Best wishes to you!
Comment #26
nallasivamkn CreditAttribution: nallasivamkn commentedthank you so much....
Comment #27
kruser CreditAttribution: kruser commentedsubscribe
Comment #28
merlinofchaos CreditAttribution: merlinofchaos commentedThe basic idea here is good. However, it should also be set up against the basic term: tid argument, since I find that to be just as (if not more) common, and the weighting matters there as well.
Also, taxonomy weighting is by weight, then name so it needs two orderby calls, not just the one.
Comment #29
mstrelan CreditAttribution: mstrelan commentedsubscribe
Comment #30
shenzhuxi CreditAttribution: shenzhuxi commentedThe patch for views-7.x-3.x-dev
Comment #31
timwoodPossibly related https://drupal.org/node/1186724
Comment #33
ofry CreditAttribution: ofry commentedI have this bug too.
In main page http://www.aprgr.ru I sort terms Гидроизоляция, Крепежи, Профлист, Сэндвич-панели, Теплоизоляция by weight. But it sorted alphabetically.
Russian alphabet:
АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ.
Drupal core 7.24
Views 7.x-3.7+20-dev (2013-Dec-24)
Comment #34
ofry CreditAttribution: ofry commentedComment #35
ofry CreditAttribution: ofry commentedMy bug has gone away after update Drupal to version 7.25.
Comment #36
ofry CreditAttribution: ofry commentedAfter adding new taxonomy term and clear all caches bug appears again :(
Comment #37
ofry CreditAttribution: ofry commentedI rerolled patch #30.
Comment #38
ofry CreditAttribution: ofry commentedPatch #37 working for me. Please review.
Comment #39
ofry CreditAttribution: ofry commented37: views-sort_by_term_weight-417312.patch queued for re-testing.
Comment #40
ofry CreditAttribution: ofry commentedRetesting patch after new commits in dev release.
Comment #41
ofry CreditAttribution: ofry commentedYes, tests passed! Needs review :)
Comment #42
nattyweb CreditAttribution: nattyweb commentedInterested in this - hoping to see a solution soon...
Comment #43
johnhanley CreditAttribution: johnhanley commentedOff-topic sidebar: You do know there's a built-in way to "subscribe" to threads now, right?
Comment #44
ofry CreditAttribution: ofry commented37: views-sort_by_term_weight-417312.patch queued for re-testing.
Comment #45
ofry CreditAttribution: ofry commentedYeah, tests passed! Needs review still :)
Comment #46
paul53181 CreditAttribution: paul53181 commentedAfter applying the patch I do not see any new options inside the contextual filter. Perhaps I'm looking in the wrong place.
Comment #47
ofry CreditAttribution: ofry commentedpaul53181: This option already exist without filter in Sorting Criteria. But without this patch sorting by weight is bugged (sometimes it sorts alphabetically instead of weight). After I apply this patch in latest dev version, I never seen this bug on view:
and other views :)
Comment #48
paul53181 CreditAttribution: paul53181 commentedI applied the patch to the current dev version of views (core 7.6) . When I sort my summary view by term weight I get no change. The sorting in the contextual filter overrides any sorting I have set in the sort criteria.
Comment #49
ofry CreditAttribution: ofry commentedI not used sorting in contextual filter... Maybe you can off sorting in contextual filter?
Comment #50
ofry CreditAttribution: ofry commented37: views-sort_by_term_weight-417312.patch queued for re-testing.
Comment #51
ofry CreditAttribution: ofry commentedpaul53181: can you give me export the view with such trouble? Thanks.
Comment #52
paul53181 CreditAttribution: paul53181 commentedComment #53
rupesh_jagtap CreditAttribution: rupesh_jagtap commentedI have tried this patch, but didn't worked for me. Checked the view SQL query but didn't found any change any 'order by' part. Also Patch has only form API code and nothing to modify default query.
If anybody is further worked on it then please post the patch.
Comment #54
antims CreditAttribution: antims commentedPatch #37 not work for me.
Comment #55
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 5 year old patch in #37 to views_handler_argument_term_node_tid.inc does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.
Comment #56
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.