I know this never got done for the D7 version, but wonder if it is possible for D8?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skitten created an issue. See original summary.

Graber’s picture

Status: Active » Needs work

Yes, it's possible. Quite complicated, but possible.

Graber’s picture

Status: Needs work » Postponed
Issue tags: +blocked

Added a child task to prepare module internal API. It'll also be a functional improvement, as it'll allow selected results to be remembered in case the config or confirm form was abandoned.

Graber’s picture

Bad news.

This will require a small API change: if an action has pass_context = TRUE annotation, the $context is passed to the action object. entity data list is one of the items in the $context array and its structure changed.

If a third-party module uses this list it'll have to adapt to this change (it was flat before and now it's an array of list arrays keyed by results page number).

One module it affects I know about is views_bulk_edit, but in this case an update can be immediate.

** EDIT **
pass_context = TRUE annotation is not required, action always has entity list in its context along with other bulk form parameters.

joelpittet’s picture

I think this may be fine to tackle, though sounds like an 8.2.x feature request IMO. Regardless there is a patch to try and do this in D7 which I'll refer here for inspiration maybe from @plach.
#1207348: Integrate multi-page selection

Graber’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

Good point. API change is tiny, but in general this will require a bit of work and some bigger code changes under the hood. 2.x branch created.

Graber’s picture

Status: Postponed » Needs work
Issue tags: -blocked
FileSize
26.17 KB

All work will be done as a part of this issue. Uploading intermediary patch to keep my work safe. It doesn't work yet, however I feel the direction is right and much has been done.

Graber’s picture

Assigned: Unassigned » Graber
FileSize
46.79 KB

This one works in my limited development testing scope and is very promising. TODO: UX improvements (multipage select info element), review tests (probably there will be a lot of failures), general code review & cleanup. API improvements are colossal, some of them will possibly make their way to 1.x as well when fully verified.

Almost there.

  • Graber committed b1204c5 on 8.x-2.x
    Issue #2929645 by Graber: Persist selection across pages
    
Graber’s picture

Status: Needs work » Needs review

Committed. Please check the 2.x branch. What I don't like is the multipage select details element, if someone with frontend/UX experience could look at it and maybe propose a better design? Also probably frontUi.js will need some polishing.

Selection is maintained regardless of sorts/exposed filters but is dropped when view arguments are changed because of unpredictable view behaviour with empty arguments (it doesn't always have to be "show all").

Also a better mechanism of getting selected view results and entities has been introduced (using row base table field values as dynamically added WHERE filters).

This will be a 2.0-beta candidate when worked on a bit more.

Graber’s picture

Assigned: Graber » Unassigned
Graber’s picture

Parent issue: » #2932173: Plan for 2.0-rc1
Graber’s picture

Graber’s picture

Status: Needs review » Fixed
Graber’s picture

Status: Fixed » Closed (fixed)

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

skitten’s picture

Just trying this out (in 2.0-rc3) and I can't seem to get it to work. The UI always says (Selected 0 items in this view) and selections aren't preserved as I go to other pages and back.

I'll poke around in the code and see if I can see what's going on.

Graber’s picture

@skitten, the only things that come to my mind at the moment are:
1. Your browser cache: when you inspect source, is the frontUi.js file included and is it the same as the one in js folder?
2. Custom theme: does your view content have the view-content class?

If there is a different cause, please try to reproduce the problem on a clean Drupal installation and share the config you're using.

skitten’s picture

Hmm, works on a fresh-clean install. Doesn't work on an otherwise clean install I updated from a few months ago.

Will investigate.

skitten’s picture

FileSize
472 bytes

Figured it out: ajax callback was using an absolute path. My test install is in a subdir.

skitten’s picture

Also, for my use case I definitely want to clear the selection when the exposed filters change. I think this should be default behavior since otherwise you can have selected items that you cannot see.

Is this simple? I assume it would involve storing the current filter in the tempstore.

Graber’s picture

I created 2 new issues:

  1. #2941553: Add an option to clear selection on exposed filters change
  2. #2941552: Persistent selection doesn't support subdirectory instances

Both shouldn't be too hard.

Thanks @skitten, feel free to update descriptions if needed.