Hello.

I have a view setup that takes an argument TermId.
I have defined a page display for node ordering named "order_page" and another for node viewing named "view_page".
The order_page has Style:Draggable Table and the "Use arguments as well as view ID to order" checked, path is "suggested/%/order".
The view_page has Style:Unformatted, path is "suggested/%".

The problem is that on the view_page the defined order from order_page isn't respected, and the DraggableViews:Order field is NULL.

Examining the generated SQL for tid=1 I see:

For order_page

SELECT node.nid AS nid,
   node.title AS node_title,
   draggableviews_structure_node0.value AS draggableviews_structure_node0_value
 FROM node node 
 INNER JOIN term_node term_node ON node.vid = term_node.vid
 LEFT JOIN draggableviews_structure draggableviews_structure_node0 ON node.nid = draggableviews_structure_node0.nid AND (draggableviews_structure_node0.delta = 0 AND draggableviews_structure_node0.view_name = 'get_ordered' AND draggableviews_structure_node0.args = '1')
 WHERE (node.status <> 0) AND (term_node.tid = 1)
   ORDER BY draggableviews_structure_node0_value ASC, draggableviews_structure_node0_value ASC

While for view_page

SELECT node.nid AS nid,
   node.title AS node_title,
   node_data_field_intro.field_intro_value AS node_data_field_intro_field_intro_value,
   node.type AS node_type,
   node.vid AS node_vid,
   draggableviews_structure_node0.value AS draggableviews_structure_node0_value
 FROM node node 
 INNER JOIN term_node term_node ON node.vid = term_node.vid
 LEFT JOIN content_field_intro node_data_field_intro ON node.vid = node_data_field_intro.vid
 LEFT JOIN draggableviews_structure draggableviews_structure_node0 ON node.nid = draggableviews_structure_node0.nid AND (draggableviews_structure_node0.delta = 0 AND draggableviews_structure_node0.view_name = 'get_ordered' AND draggableviews_structure_node0.args = '')
 WHERE (node.status <> 0) AND (term_node.tid = 1)
   ORDER BY draggableviews_structure_node0_value ASC

So the misbehaviour lies to draggableviews_structure_node0.args = ''.

In fact, even if I set the view_page's style to Style:Draggable Table, but leave the "Use arguments as well as view ID to order" unchecked, I am getting the same behaviour.

Is this really a bug or I am missing something? Any clues then about how to go about it?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tri’s picture

Title: Defined order not respected when Style different than Draggable Table » DraggableViews:Order field unavailable when Style different than Draggable Table

Sorry about that:
On the view_page, the DraggableViews:Order field is not NULL, it is just an ordering number different from the one defined at the order_page.

So the main problem remains the same.

Tri’s picture

Title: DraggableViews:Order field unavailable when Style different than Draggable Table » Defined order not respected when Style different than Draggable Table
sevi’s picture

Title: DraggableViews:Order field unavailable when Style different than Draggable Table » Defined order not respected when Style different than Draggable Table
FileSize
902 bytes

Mmm, there's no way to make settings for other displays. So should they always use arguments, or not?
I'll have to think about this a little more. But in the meanwhile the attached patch should make it:
The argument will be used in queries for all displays whenever an argument is present (except it is not checked at the Draggable table settings).

THIS IS NOT THE FINAL SOLUTION.
Before you use this patch you'll have to update to the latest dev version. (I recently committed some form-api changes; not relevant for this issue).

Tri’s picture

Thanks sevi,your patch made it indeed.

Considering your questioning:

Since I don't know much about Views plug-in authoring I can't follow your coherence. If it boils down to decision making, giving some insight about the pros and cons of each solution would help me add my two cents.

sevi’s picture

Everytime a view gets built the following function gets called:

views/draggableviews.views.inc:

function draggableviews_views_query_alter(&$view, &$query) {
  for ($i = 0; $i < 2; $i++) {
    if (isset($query->table_queue['draggableviews_structure_'. $view->base_table . $i])) {
      $query->table_queue['draggableviews_structure_'. $view->base_table . $i]['join']->extra[] = array(
        'field' => 'view_name',
        'operator' => '=',
        'value' => $view->name,
      );
      $args = NULL;
      if (!isset($view->style_plugin->options['draggableviews_arguments']['use_args']) || !empty($view->style_plugin->options['draggableviews_arguments']['use_args'])) {
        if (!empty($view->args)) {
          $args = implode('/', $view->args);
        }
      }
      $query->table_queue['draggableviews_structure_'. $view->base_table . $i]['join']->extra[] = array(
        'field' => 'args',
        'operator' => '=',
        'value' =>  $args, 
      );
    }
  }
}

The line with the options['draggableviews_arguments'] is relevant.
Every time this functions gets called I've to decide whether the "args" should be used to build the query or not. The information I have at this point:

  • Which view is beeing built
  • Which display is beeing built

If the display to build USES "Draggable Table" style plugin it's easy:
I just read the configuration settings of the style-plugin of this display.

But if the display to build DOES NOT USE "Draggable Table" style plugin we have a problem:
There might be another display that uses "Draggable Table" style plugin in this view. But we don't know. Is there such a display? Does the style-plugin of this display is configured to use arguments?

Summerized:
On the one hand all views displays are independent and don't deal with each other.
On the other hand DraggableViews Native handler offers "DraggableViews: Order" (a field) that is the same for all displays.

I cannot assume that the user wants all displays to use arguments because only one of the displays does.

Does this helps understanding the problem? :)

Tri’s picture

It's getting clearer now. This is what I think:

Is there such a display?

We can assume that there is such a display, otherwise there is no point to sort on a non existent "DraggableViews: Order" field.

Does the style-plugin of this display is configured to use arguments?

For this we have to think more specific that the general Views plugin model. The very essence of DraggableViews is to help someone provide order for a set. I believe the most common use case scenario is to built a view to make up the set, built a DraggableViews display to provide the order and then any number of other displays to view this ordered set in anyway you wish. I think that the responsibility to keep arguments consistent between all displays that use "DraggableViews: Order" and the DraggableViews display that creates that order, must be delegated to the user. If he wants something else, he is free to built another view to suit his needs. So under this light, it is safe to

assume that the user wants all displays to use arguments because only one of the displays does

, because that one display provides the needed order which he was after in the first place...

My conclusion:
Since DraggableViews Native handler offers a field "DraggableViews: Order" that is the same for all displays, those displays that use it, can't be kept independent anymore and is up to the user to keep things in sync, under the scope of a singe view.
That "DraggableViews: Order" field is a special field since it originates from within the view itself and not from an external source such as a node or a user, so i believe is logical for the one how wants to use it, to pose some limitations upon his freedom.

I hope my two cents will help you solve this decision making problem... Let me know if am missing something from the picture.

sevi’s picture

Many thanks for digging so deep to reveal the core of the matter. I just nodded my head in agreement while I was reading your answer :)

If any display uses arguments (and defines the "DraggableViews: Order" field; Native handler assumed) all unconfigured displays (non-"Draggable Table"-style-plugins) will use arguments in their queries too.

Right?

sevi’s picture

Status: Active » Needs review
FileSize
2.47 KB

Ok,
the attached patch should do it.

After committing I'll mention this in documentation.

Greetings,
sevi

Tri’s picture

I am really glad that my reasoning helped you solve this.
Dedicating some brain circles on this was the least thing I could do to contribute in your project. :)

The patch implements the point right: I have tested it with 1,2 and 3 arguments and with several display styles, it always works as long long as you keep the arguments consistent between all displays.

I am tempted to switch status to RTBC, but I don't know how much of a community I make by myself... Maybe someone has to try it also... What do you think Sevi?

sevi’s picture

Status: Needs review » Fixed

I think that a software developer sometimes has to be bold. He has to take a chance even if it could mean a loss (serious self-reviewing assumed).
As far as I can remember is this roughly what Dries Buytaert told us last Wednesday while opening the Drupal Conference in Paris.

So I scrape all my boldness together and commit this patch now :)

Thanks for reviewing,
greetings,
sevi

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

windmaomao’s picture

Version: 6.x-3.2 » 7.x-2.x-dev

this is D7, but when i try to apply this patch on 7.x-2.x-dev. i got this errors.

patching file draggableviews.views.inc
Hunk #1 FAILED at 112.
Hunk #2 FAILED at 154.
2 out of 2 hunks FAILED -- saving rejects to file draggableviews.views.inc.rej

I'm really puzzled, since i can't even find draggableviews_views_query_alter function in views/draggableviews.views.inc file, how exactly this patch is generated ? Please advice. thank you

It seems to me this patch is against 1.x branch, and it's been removed from 2.x branch !!