Cannot get DraggableViews working with contextual filters

Created on 18 February 2021, over 3 years ago
Updated 5 March 2024, 9 months ago

Problem/Motivation

Once I enable contextual filters, the view is not sorted by Draggableviews.
I would like to show members related to a specific location (term) in the order.

langcode: en
status: true
dependencies:
  config:
    - core.entity_view_mode.node.teaser
    - node.type.member
    - system.menu.admin
    - user.role.administrator
    - user.role.webmaster
  module:
    - draggableviews
    - node
    - user
id: members
label: Members
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: perm
        options:
          perm: 'access content'
      cache:
        type: none
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: ''
          query_tags: {  }
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      pager:
        type: none
        options:
          items_per_page: 0
          offset: 0
      style:
        type: default
      row:
        type: 'entity:node'
        options:
          view_mode: teaser
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          entity_type: node
          entity_field: title
          label: ''
          alter:
            alter_text: false
            make_link: false
            absolute: false
            trim: false
            word_boundary: false
            ellipsis: false
            strip_tags: false
            html: false
          hide_empty: false
          empty_zero: false
          settings:
            link_to_entity: true
          plugin_id: field
          relationship: none
          group_type: group
          admin_label: ''
          exclude: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_alter_empty: true
          click_sort_column: value
          type: string
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
      filters:
        status:
          value: '1'
          table: node_field_data
          field: status
          plugin_id: boolean
          entity_type: node
          entity_field: status
          id: status
          expose:
            operator: ''
            operator_limit_selection: false
            operator_list: {  }
          group: 1
        type:
          id: type
          table: node_field_data
          field: type
          value:
            member: member
          entity_type: node
          entity_field: type
          plugin_id: bundle
          expose:
            operator_limit_selection: false
            operator_list: {  }
        langcode:
          id: langcode
          table: node_field_data
          field: langcode
          relationship: none
          group_type: group
          admin_label: ''
          operator: in
          value:
            '***LANGUAGE_language_interface***': '***LANGUAGE_language_interface***'
          group: 1
          exposed: false
          expose:
            operator_id: ''
            label: ''
            description: ''
            use_operator: false
            operator: ''
            operator_limit_selection: false
            operator_list: {  }
            identifier: ''
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
            reduce: false
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          entity_type: node
          entity_field: langcode
          plugin_id: language
      sorts:
        weight:
          id: weight
          table: draggableviews_structure
          field: weight
          relationship: none
          group_type: group
          admin_label: ''
          order: ASC
          exposed: false
          expose:
            label: ''
          draggable_views_reference: 'members:page_1'
          draggable_views_null_order: after
          plugin_id: standard
      title: 'Related Members by location'
      header: {  }
      footer: {  }
      empty: {  }
      relationships: {  }
      arguments:
        field_location_target_id:
          id: field_location_target_id
          table: node__field_location
          field: field_location_target_id
          relationship: none
          group_type: group
          admin_label: ''
          default_action: 'not found'
          exception:
            value: all
            title_enable: false
            title: All
          title_enable: false
          title: ''
          default_argument_type: fixed
          default_argument_options:
            argument: ''
          default_argument_skip_url: false
          summary_options:
            base_path: ''
            count: true
            items_per_page: 25
            override: false
          summary:
            sort_order: asc
            number_of_records: 0
            format: default_summary
          specify_validation: true
          validate:
            type: none
            fail: 'not found'
          validate_options: {  }
          break_phrase: false
          not: false
          plugin_id: numeric
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
  business_unit_related_members_block:
    display_plugin: block
    id: business_unit_related_members_block
    display_title: 'Related members by business unit block'
    position: 2
    display_options:
      display_extenders:
        simple_sitemap_display_extender: {  }
      display_description: ''
      title: 'Related Members by business unit'
      defaults:
        title: false
        arguments: false
      arguments:
        field_business_unit_target_id:
          id: field_business_unit_target_id
          table: node__field_business_unit
          field: field_business_unit_target_id
          relationship: none
          group_type: group
          admin_label: ''
          default_action: default
          exception:
            value: all
            title_enable: false
            title: All
          title_enable: false
          title: ''
          default_argument_type: node
          default_argument_options: {  }
          default_argument_skip_url: false
          summary_options:
            base_path: ''
            count: true
            items_per_page: 25
            override: false
          summary:
            sort_order: asc
            number_of_records: 0
            format: default_summary
          specify_validation: true
          validate:
            type: none
            fail: 'not found'
          validate_options: {  }
          break_phrase: false
          not: false
          plugin_id: numeric
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
  location_related_members_block:
    display_plugin: block
    id: location_related_members_block
    display_title: 'Related members by location block'
    position: 1
    display_options:
      display_extenders:
        simple_sitemap_display_extender: {  }
      display_description: ''
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
  page_1:
    display_plugin: page
    id: page_1
    display_title: Draggableviews
    position: 3
    display_options:
      display_extenders:
        simple_sitemap_display_extender:
          variants: {  }
      display_description: ''
      title: 'Re-order members'
      defaults:
        title: false
        access: false
        arguments: false
        style: false
        row: false
        fields: false
      path: admin/content/members
      access:
        type: role
        options:
          role:
            administrator: administrator
            webmaster: webmaster
      menu:
        type: normal
        title: 'Sort members'
        description: ''
        expanded: false
        parent: system.admin_content
        weight: 0
        context: '0'
        menu_name: admin
      arguments: {  }
      style:
        type: table
        options:
          grouping: {  }
          row_class: ''
          default_row_class: true
          override: true
          sticky: false
          caption: ''
          summary: ''
          description: ''
          columns:
            title: title
          info:
            title:
              sortable: false
              default_sort_order: asc
              align: ''
              separator: ''
              empty_column: false
              responsive: ''
          default: '-1'
          empty_table: false
      row:
        type: 'entity:node'
        options:
          view_mode: teaser
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: false
            ellipsis: false
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: string
          settings:
            link_to_entity: true
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: node
          entity_field: title
          plugin_id: field
        draggableviews:
          id: draggableviews
          table: node_field_data
          field: draggableviews
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          action_title: Action
          include_exclude: exclude
          selected_actions: null
          entity_type: node
          entity_field: nid
          plugin_id: draggable_views_field
    cache_metadata:
      max-age: 0
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - 'user.node_grants:view'
        - user.roles
      tags: {  }

🐛 Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

🇧🇪Belgium stijnstroobants Leuven

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia stephenrodrigo@yahoo.com Melbourne

    The, problem for this is the ARGS column in the draggableviews_structure table. In Draggable views 8.X versions, the arguments were saved in the ARGS column. Therefore, sorting were based on arguments of the URLs. This was working perfectly with Drupal 7.

    When you inspect the draggableviews_views_submit hook. You will see the $view_args will be set from $view->args
    $view_args = !empty($view->args) ? json_encode($view->args) : '[]'

    But, this is wrong, $view_args should be set from the exposed filters.

    I

  • 🇪🇸Spain bmunslow

    But, this is wrong, $view_args should be set from the exposed filters.

    I think this is a big assumption to make, since not all views with contextual filters may have those filters exposed.

    Good thing is draggableviews provides a hook to alter the view arguments if needed for a specific scenario, like the one you mentioned.

    In my case, I use contextual filters for the Draggableviews Order page, but I display the results in a block that is rendered by means of the viewsreference_filter module, which exposes the filter instead of using contextual filters.

    I was able to work around it by implementing the following hook_draggableviews_join_withargs_alter() as follows:

     /**
     * Implements hook_draggableviews_join_withargs_alter().
     */
    function MY_MODULE_draggableviews_join_withargs_alter(&$view_args, &$context) {
      if (empty($view_args)) {
        // Give draggable view a chance to use exposed filters as arguments,
        // since these may have been passed on from viewsreference_filter module.
        if (!empty($context['view_query']->view->exposed_raw_input)) {
          $view_args = array_values($context['view_query']->view->exposed_raw_input);
        }
      }
    }
    

    In addition, I had to apply the RTBC patch in this issue: https://www.drupal.org/project/draggableviews/issues/3336466 🐛 "Pass Contextual Filters" option is broken on multiple sorts RTBC

Production build 0.71.5 2024