Hello,

I have these two vocabularies associated with a particular content (node) type:

Levels: with terms like (first, second, third etc...)
Topics: with terms like (internet, linux, php, mysql etc...)

I have set up a custom view to display the nodes of that particular content type. The view displays nodes' titles, body, attachments etc.. It also should list (for each node) all the terms associated with it (which is usually one term from the vocabulary "Levels" and one from the vocabulary "Topics"). To do that I have configured the view to display the field "Taxonomy: All terms".

The list shows but the problem is that the two terms (each from a different vocabulary) get sorted alphabetically across. This means, something like this:

For node 1:
internet, second

For node 2:
first, linux

For node 3:
mysql, third

What I want to do is to always show Level vocabulary's terms first and then terms from the second vocabulary (Topics). Desired output should look like this:

For node 1:
second, internet

For node 2:
first, linux

For node 3:
third, mysql

Thanks in advance for any ideas.

Comments

dawehner’s picture

Category: support » feature
Status: Active » Needs review
StatusFileSize
new2.11 KB

This is not possible at the moment but it's possible with a feature request.

Personally i doubt that this will be commited to the 6.x-2.x branch, but let's see.
Please test the patch.

W.M.’s picture

@dereine

On target! It works exactly the way it should. Thanks for all the efforts.

I am looking into doing something like this:

Levels: "Third (linked to term's custom path)" Topics: "MySQL (linked in same manner)"

That is to say, voc 1 name first then linked term, and then voc 2 name followed by term linked.

I have looked at this page for a possible solution:

http://11heavens.com/putting-some-order-in-your-terms

I will try to do it this way, but I am not sure if this would work when using a custom view (or whether it is going to interfere with your work).

I will be looking into this later. Main result obtained. I am very grateful! Thanks!

mandreato’s picture

Hi, I've a similar need:
the content type is linked to three vocabulary (V1, V2, V3) and every vocabulary has its own weight (V1=1, V2=2, V3=3). Then the linked terms are (T1 from V1, T2 from V2 and T3 from V3) and every term has its own weight relative to its vocabulary.
It happens that T1 has weight=2, T2 has weight=1 and T3 has weight=1.
Since the All Terms field shows the terms ordered by term's weight, they are listed as T2, T3, T1, ...
Instead, I need to list them as T1, T2, T3.

I've tried to manually apply this patch to 6.x-3.x-dev, but the view continues to show T2, T3, T1.
I've also changed the following:

      if (!empty($this->options['order_vocabulary'])) {
        $order[] = 'v.weight'; // weight insted of vid
      }

but had no effects.

Is the patch applicable to 6.x.3 or maybe it does need an adjustment ?

Thanks In Advance.

dawehner’s picture

As long you don't post a new patch it's hard to guess where you added this etc.
At least the previous commend said it worked.

mandreato’s picture

I've basically tried to apply your #1 patch to a 6.x-3.x-dev environment.
Since the patch is for 6.x-2.x, I installed it manually on the 6.x-3 views_handler_field_term_node_tid.inc file by commenting the "-" lines and adding the "+" lines.
The only difference I've done is putting "v.weight" instead of "v.vid" on the line 33, because I need a vocabulary weight ordering.

Since I'm a newbie on Drupal/PHP world, It is very likely that I've done some mistake... So before saying that the patch is not working on Views 6.x-3, I'm asking if it is possible to have a 6.x-3.x-dev version from a more experienced developer than me ;-)
I'll test it.

Thanks for you patience.

mandreato’s picture

Excuse me if I'm still here to bother... this is making me crazy.
I'm trying to update the pre_render function of views_handler_field_term_node_tid class on a 6.x-3.x environment, but it seems to sort no effects (BTW, I've replicated the same behaviour on a 6.x-2 env).

For example: I have a view where a "Taxonomy: All terms" field is present. When I press the preview button, it is showing all correctly (apart the sorting issue I'm trying to get rid of).
So I change the code of pre_render function, leaving only this:

  function pre_render($values) {
    print "test";
  }

But no "test" string is shown, nor an exception is raised.
Instead, if I try the same thing on function render_item, pressing the preview button throws immediately an error. So pre_render is not used in this case ?
I've tried to save, clear the cache, etc.
... I'm disoriented...
How can I debug my updates on pre_render function ?

W.M.’s picture

Try to use Linux patch utility on the target file. That's a way to make sure the file get patched as it should.

I wish you good luck.

mandreato’s picture

I'm on a XAMPP Windows development environment...

mandreato’s picture

OK, I finally found why patch updates aren't visible on view behaviour: Internationalization Views module is installed so pre_render function is extended by i18nviews_handler_field_term_node_tid class (...\sites\all\modules\i18nviews\includes\i18nviews_handler_field_term_node_tid.inc).
Indeed, editing i18nviews_handler_field_term_node_tid.inc does the trick !
I've learned a lot during these days ;-)

As a result, the #1 patch doesn't works if i18nviews is installed: the new "Order by vocabulary" option is shown on the view edit page, but it's not considered during rendering.

Now there are three possible scenarios:
1) who is not using i18nviews can apply the patch (which is working under those conditions)
2) who uses i18nviews and applied the patch, must also propagate the changes to i18nviews_handler_field_term_node_tid.inc
3) this patch is commited to Views and another issue is opened on Internationalization Views queue to ask for similar patch (new functionality transposition)

Final suggestion: adding "Order by vocabulary" feature should have two options: order by vocabulary ID (as in this patch) and order by vocabulary weight.

In the meantime, I'll update both modules locally...
Hope This Helps.

Peng.Pif’s picture

Hi, I applied the patch in #1 using Views 6.x-2.12 Drupal 6.20.

Works perfect. Thank you!!

W.M.’s picture

@Peng.Pif

Thanks. I am glad it works for you too. I hope the patched code (#1) will find its way to next stable release.

Thanks dereine.

mxt’s picture

I need this feature too, and I'm also using i18nViews: does the scenario 3 suggested by mandreato in #9 feasible ?

mxt’s picture

Ok, I can confirm that patch in #1 does correctly the job, and what mandreato suggested in #9 works fine.

So, I made the following operation, useful for who is searching this funtionality and is using i18nViews also:

  1. Applied patch in #1
  2. Change $order[] = 'v.vid'; to $order[] = 'v.weight'; if you want to sort by vocabolary weight
  3. Propagate the same changes to i18nviews_handler_field_term_node_tid.inc

And all works fine.

I think that the suggestion provided by mandreato: "... adding "Order by vocabulary" feature should have two options: order by vocabulary ID (as in this patch) and order by vocabulary weight." has to be added to this patch before committing it.

mandreato’s picture

I 100% agree with #13

mxt’s picture

I was thinking, it makes sense to sort by v.vid? I think the sort by v.weight is the correct choice for all cases. The parameter "weight" exists for this purpose in vocabularies.

So I think the patch # 1 should be amended by changing $order[] = 'v.vid' to $order[] = 'v.weight' definitively.
(and thus the label would be "Order by vocabulary WEIGHT")

What do you think about it?

dawehner’s picture

Status: Needs review » Needs work

This makes sense. Feel free to change the patch

mxt’s picture

Status: Needs work » Needs review
StatusFileSize
new2.13 KB

Ok, I've manually modified the original patch: I'm not a programmer so I hope that everything is ok (works for me).

mxt’s picture

Title: Displaying the field "Taxonomy: All terms" sorted by vocabulary type. Possible ?! » Displaying the field "Taxonomy: All terms" sorted by vocabulary type. Possible ?! [INCLUDE WORKING PATCH]
Status: Needs review » Reviewed & tested by the community

I've just used this patch in another site and works very well.

Can this be committed please?

Thank you very much.

dawehner’s picture

Version: 6.x-2.12 » 6.x-3.x-dev

It will probably be comited to 6.x-3.x but not to 2.x as 6.x-2.x is in a critical-buf-fix-only-modus.

mandreato’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.4 KB

I've created a patch against 6.x-3.x-dev.
Also added a join with term_hierarchy to consider first level hierarchy on order by (managing more than first level is more difficult).
When (if) this will be commited, I'll provide another patch on i18n_views queue.

mustanggb’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)