Can patterns manage this via the views tag? Or does a custom form tag option need to be set?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cdale’s picture

Title: How to handle override options on views? » Add views display overrides option.
Component: Documentation » Code
Category: support » feature
Status: Active » Needs review
FileSize
915 bytes

I've created a small patch which achieves this. My first attempt was trying to use the Form API to call the correct override action, then call the form again to save the value, but this proved difficult to get to work, so I've opted with just doing what the override submit handler does. It works well.

Example usage is as follows:

  -
    tag: view
    action: update
    details:
      name: test
      description: Test view
      tag: test
      base: node
    display:
      - name: default
        section:
          - section: title
            value: Test
          - section: row_plugin
            value: node
          - section: row_options
            value:
              relationship: none
              build_mode: teaser
              links: 1
              comments: 0
          - section: use_pager
            value: 1
        item:
          - type: filter
            name: node.type
            data:
              operator: in
              value:
                page: page
          - type: filter
            name: node.status
            data:
              operator: =
              value: 1
          - type: sort
            name: views.random
      - name: page
        section:
          - section: path
            value: random-path
          - section: menu
            value:
              type: normal
              title: Click me
              name: primary-links
      - name: block
        section:
          - section: items_per_page
            value: 2
            override: true                              <-- Override items_per_page on block to have a different value than the rest of the view displays.
          - section: use_pager
            value: 0
            override: true                              <-- Override use_pager on the block also.
          - section: block_description
            value: Testimonials
cdale’s picture

Oops. That example YAML needs to remove the second override option, as views overrides all those items together....

cdale’s picture

I've change the patch, so that it now handles override options on the display settings, as well as the handlers. I've also added the ability to remove handlers as I couldn't see this done anywhere. There is also a bug fix for getting the correct display id on the item for update actions. Sorry for bundling this all together. I can break them out into separate patches if it is an issue.

This patch can be used with the following pattern to have a default and page view using a node.created sort handler, and a block using a views.random sort handler.

-
    tag: view
    action: update
    details:
      name: test
      description: The test view
      tag: test
      base: node
    display:
      - name: default
        section:
          - section: title
            value: Test
          - section: row_plugin
            value: node
          - section: row_options
            value:
              relationship: none
              build_mode: teaser
              links: 1
              comments: 0
          - section: use_pager
            value: 1
        item:
          - type: filter
            name: node.type
            data:
              operator: in
              value:
                page: page
          - type: filter
            name: node.status
            data:
              operator: =
              value: 1
          - type: sort
            name: node.created
            data:
              order: DESC
              granularity: minute
      - name: page
        section:
          - section: path
            value: test
          - section: menu
            value:
              type: normal
              title: Test
              name: primary-links
      - name: block
        section:
          - section: items_per_page
            value: 2
            override: true
          - section: use_pager
            value: 0
          - section: block_description
            value: Test
        item:
          - type: sort
            section: sorts
            override: true
          - type: sort
            name: node.created
            action: remove
          - type: sort
            name: views.random
cdale’s picture

FileSize
2.39 KB

Forgot the patch

vaish’s picture

Status: Needs review » Needs work

I'm really sorry for not getting to this earlier. This was very much needed addition to the views component. Patch committed.

I'm marking this issue as "needs work" because re-running the pattern produces some weird results: all sort options are removed for all the displays and options that were overridden by block display end up applied to all other displays as well. There is a good chance that this is not directly related to this patch but definitely something that we should try to fix. I'm not sure when I will have a time to look into this further.