According to the documentation DraggableViews should include the view's arguments in the saved data, so per argument the ordering can be saved. In the Drupal 8 version of DraggableViews this is not the case. Args is always filled with '[]' and ignored when joining the view.

I'll attach a patch to fix this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Rolf van de Krol created an issue. See original summary.

Rolf van de Krol’s picture

Status: Active » Needs review
FileSize
2.78 KB

Patch

iStryker’s picture

Status: Needs review » Needs work

Need test to test this. Probably another view added to Draggableviews Demo module, then another test added to test it.

iStryker’s picture

Adding this to 8.x-1.1 release

friera’s picture

FileSize
2.76 KB

I provide and updated patch to solve that.

nicrodgers’s picture

FileSize
3.02 KB
856 bytes

Patch works great, thanks! I've added in a call to \Drupal::moduleHandler()->alter() to give other modules a chance to edit or ignore some of the view args. In our case, this was a really useful addition.

Still needs tests though so leaving as needs work.

nicrodgers’s picture

FileSize
3.02 KB

Re-uploading the patch from #6, due to some weird caching issues on d.o.

sheise’s picture

Thanks! I'm using the patch from #7 and everything seems to be working as it should.

stephenebersole’s picture

Yes, Thank you for patch #7. We have a site in development where we have a view of products contextually filtered by taxonomy. Prior to this patch when we set the order on one contextually filtered page, it would affect other contextually filtered pages. This patch resolved the issue for us!

johnnybgoode’s picture

Thanks for the work here everyone! The patch in #7 works great with views using contextual filters. I had a use case where I needed to create a draggable view with an exposed filter to allow users to sort posts by category, so I've updated the patch to include exposed filters in the `args` data as well.

rhovland’s picture

#10 works well

One thing I realized while testing is that this is potentially breaking functionality on existing sites. Pages that have arguments would lose their sorting because context has changed, and they don't exist.

To not break existing sites and make this more useful we need control over what arguments are used. By default arguments would not be enabled. When adding a sort to a view using draggableviews data you would check boxes next to which arguments you want to use.

zanvidmar’s picture

If you have two instances of same view (id and display) on same page, with different arguments, draggable function does not work because html id is identical. This patch is fixing that issue.

I updated it as addition to patch #10 and as standalone patch.

Update: this patch only works with https://www.drupal.org/project/draggableviews/issues/2867348. In the next comment it is fixed patch

zanvidmar’s picture

mErilainen’s picture

I started to get duplicates after applying the patch and saved the listing in two languages, see the attached screenshot. For some reason there is an empty array "[]" saved along with the "langcode" parameter. If I come to the view and the default value "English" is selected, I don't have any value in the url, and this is saved as two empty arrays "[][]" to the database. This is not visible in the screenshot though.

nicrodgers’s picture

FileSize
3.02 KB

I wonder if it's better to limit the scope of this issue to just contextual filters, as per the patch in #7 and deal with exposed filters in a separate follow-up? Here's a re-roll of #7 for the latest 1.x-dev.

iStryker’s picture

mErilainen is correct, Patch #10 wil add two [][] because of

+  public function buildJoin($select_query, $table, $view_query) {
+    $view_args = !empty($view_query->view->args) ? json_encode($view_query->view->args) : '[]';
+    $view_args .= !empty($view_query->view->getExposedInput()) ? json_encode($view_query->view->getExposedInput()) : '[]';

Re-rolling #15 and committing (after testing).

Exposed filters can be moved to a separate issue.

  • iStryker committed 6a92798 on 8.x-1.x authored by nicrodgers
    Issue #2903567 by zanvidmar, nicrodgers, Rolf van de Krol, friera,...
iStryker’s picture

Attached is re-rolled patch (with code cleanup of WithArgs.php)

iStryker’s picture

Adding related issue to fix expose filters

deepaksingh05’s picture

Patch #18 not working for me.
Patch "draggableviews-args-not-working-2903567-13-D8.patch" is working for me only for reordering on the sorting page.
But the rendering Views is not able to get the draggable weight, getting weight = 0, and content not reflecting in an ordered manner.
It was working perfectly before my Drupal core didn't update to 8.8.

Ralf Eisler’s picture

The problem still exists with the actual dev version of the module.

I am working with:
-- Drupal 8.8.0 and
-- DraggableViews 8.x-1.2+8-dev (2019-Dec-06)

For the installation and configuration I followed the instructions in the README.md file.

I configured several views with node listings and the according views to change the order in which the nodes are displayed.

First problem: The DraggableViews Weight sort criteria does not display a weight value in the view to reorder the nodes. “Show row weights” shows empty fields.

Error message:

Notice: Undefined property: Drupal\views\ResultRow::$draggableviews_structure_weight in Drupal\draggableviews\Plugin\views\field\DraggableViewsField->viewsForm() (line 124 of /my-website.localhost/docroot/modules/contrib/draggableviews/src/Plugin/views/field/DraggableViewsField.php) #

Second problem: I configured several views to display nodes:

There is the following text in the README.md file there should be an option to choose the title of a view for reordering a specific list:

*Things to confirm after you saved your new view.
- In the Administrative Views UI, Go back to your View's 'page' display.
-> Click 'Draggableviews: Weight (asc)' under 'SORT CRITERIA'
-> You should see:
Display sort as:
()

This option does not show up.

iStryker’s picture

@Thomas unless your issue relates to this issue, do not post in a comment here. Please open a new issue.

Status: Fixed » Closed (fixed)

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

alison’s picture

Seeing #20 from @deepaksingh05 -- has anyone else had a change in effectiveness of this fix since updating Drupal core to 8.8.x (from 8.7.x)?

The draggable weights aren't working for me on view page displays with a contextual filter/argument in the URL (i.e. /people/25 where 25 is a term ID) -- I tried adding the draggableviews weight value as a field to the view, and even in the view preview, it just says "0" for each view result (when I clear the argument in the view preview, the draggableviews weight values show and sort properly).

...But I don't know if this problem was happening before 8.8.x, I didn't have this particular view situation back then :-/ Anyway, figured I'd ask!

(EDIT: I do have the latest dev version.)

ghaya’s picture

I seem to have a similar problem to #24. After a recent update to 8.92 my draggable views with arguments stopped sorting. I am not sure exactly when the sorting stopped working so it may have even been with a previous update.

Revision: I hade the latest dev version installed, the sorting started working again when I went back to the stable version and applied this patch https://www.drupal.org/files/issues/2903567-07-args.patch