Add config actions for views

Created on 24 August 2022, over 2 years ago
Updated 21 May 2024, 7 months ago

Problem/Motivation

While ๐Ÿ“Œ Determine which core config entity methods should be config actions Fixed will be straightforward for some of the more basic configuration entities, for others it will be relatively complex. Not surprisingly, views is on the complex end of the spectrum.

Our best indicator for concrete use cases is looking to core config that's been overridden in an install profile, since that provides a concrete use case. So an initial exercise to begin to scope config actions requirements for looking at how core's module-provided views such as views.view.taxonomy_term.ymlhave been overridden in the demo_umami profile.

Sample diffs run from the root of a Drupal core repo:

diff -u core/modules/node/config/optional/views.view.frontpage.yml core/profiles/demo_umami/config/install/views.view.frontpage.yml
diff -u core/modules/taxonomy/config/optional/views.view.taxonomy_term.yml core/profiles/demo_umami/config/install/views.view.taxonomy_term.yml

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ“Œ Task
Status

Active

Version

11.0

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada nedjo

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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States thejimbirch Cape Cod, Massachusetts
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    Should this issue be moved to Drupal project?

  • @admitriiev opened merge request.
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    Uploading patch to use in Drupal CMS for config actions on views, that need to add/remove/update filters/fields and other options of the display.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    The MR contains 3 new config actions for view entity type:

    1. setDisplayOption - allows to set a display option like filters, fields, pager, etc .
    Parameters:
    option (required) - the name of the option to manage, can be filters, fields, pager, etc (any option that view display can have)
    settings (required) - the option settings. This varies from option type.
    display_id (optional) - the display id, if non is provided the default is used.
    Example usage:

    view.view.my_view:
      setDisplayOption:
        display_id: default
        option: pager
        settings:
          type: mini
          options:
            offset: 0
            pagination_heading_level: h4
            items_per_page: 10
            total_pages: null
            id: 0
            tags:
              next: โ€บโ€บ
              previous: โ€นโ€น
            expose:
              items_per_page: false
              items_per_page_label: 'Items per page'
              items_per_page_options: '5, 10, 25, 50'
              items_per_page_options_all: false
              items_per_page_options_all_label: '- All -'
              offset: false
              offset_label: Offset
    

    2. addItemToDisplayOption allows to add the item to views display option. The difference from setDisplayOption is that the existing option settings are preserved and only the new item is added to the option settings.
    Parameters:
    The same as for setDisplayOption, plus one more item - for the name of the item to add.
    Example usage:

        views.view.drupal_cms_search:
          addItemToDisplayOption:
            display_id: default
            option: filters
            item: facets_type
            settings:
              id: facets_type
              table: search_api_index_drupal_cms
              field: facets_type
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: facets_filter
              operator: '='
              value: ''
              group: 1
              exposed: true
              expose:
                operator_id: ''
                label: 'Content type'
                description: ''
                use_operator: false
                operator: ''
                operator_limit_selection: false
                operator_list: { }
                identifier: type
                required: false
                multiple: true
                remember_roles:
                  authenticated: authenticated
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: { }
                group_items: { }
              hierarchy: false
              label_display: visible
              facet:
                query_operator: or
                min_count: 1
                show_numbers: true
                processor_configs:
                  translate_entity:
                    weights:
                      build: 5
                    settings: { }
    

    3. removeItemFromDisplayOption allows to remove the item from views display option.
    Parameters:
    The same as for addItemToDisplayOption, minus one settings as it is not needed for item that is removed.
    Example usage:

        views.view.drupal_cms_search:
          removeItemFromDisplayOption:
            display_id: default
            option: filters
            item: facets_type
    
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    I have also exposed 2 methods from view entity class: addDisplay and duplicateDisplayAsType as Action Methods to use as config actions.

  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    There are some tests with blocks that are failing, I assume not related to the tests form MR.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nmudgal

    Looks like it was just a fluke. Rerunning the pipeline resolved the failing test issue.

  • Hi,
    Please add steps to reproduce to test.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    For testing you need to create a recipe and use the config actions from comment https://www.drupal.org/project/drupal/issues/3305859#comment-15847932 โ†’ . The MR also contains tests, you can follow them as well.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    This is a Drupal CMS stable release blocker for the search filters recipe ๐Ÿ“Œ Add recipe for search facets Active , as we don't want any patch. I think that's an optional recipe, so might be just "Drupal CMS release target" instead. Feel free to recategorize.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States phenaproxima Massachusetts

    This does not block a stable release of Drupal CMS; the MR you referenced will not be in Drupal CMS 1.0.0, because it couldn't land before the RC1 deadline due to its reliance on this patch.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States phenaproxima Massachusetts

    Reviewed. I think this is a reasonable start but I would suggest cutting back the scope ("remove" is a hard thing to get committed, and it's not clear how necessary/useful that is here) and greatly improving the documentation/examples to make it clear how to actually use these actions. Views are utterly inscrutable for many reasons, and we want to make sure it's plain as day how these actions are meant to be used.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

    I have removed config action that removes display option items from MR. I have also combined setDisplayOption with addItemToDisplayOption config actions. Here is the updated usage documentation:

    setDisplayOption config action has following parameters:

    option (required) - the name of the option to manage, can be filters, fields, pager, etc (any option that view display can have)
    settings (required) - the option settings. This varies from option type.
    display_id (optional) - the display id, if non is provided the default is used.
    override (optional, default FALSE) - allows to override the display option (make it only for the current display)
    item (optional) - in case of fields and filters, it is possible to add/update the individual field/filter providing the name of the field/filter here. The settings parameter will be applied to this individual item instead of the display option itself.
    allow_update (optional, default TRUE) - this is optional parameter to forbid of field/filter (individual item of a display option) update in case the item already exists in a view.

    Example usage:

    1. Change the pager

    view.view.my_view:
      setDisplayOption:
        display_id: default
        option: pager
        settings:
          type: mini
          options:
            offset: 0
            pagination_heading_level: h4
            items_per_page: 10
            total_pages: null
            id: 0
            tags:
              next: โ€บโ€บ
              previous: โ€นโ€น
            expose:
              items_per_page: false
              items_per_page_label: 'Items per page'
              items_per_page_options: '5, 10, 25, 50'
              items_per_page_options_all: false
              items_per_page_options_all_label: '- All -'
              offset: false
              offset_label: Offset
    

    2. Add a field to a view:

      view.view.my_view:
        setDisplayOption:
          display_id: default
          option: fields
          item: my_field_id
          settings:
             alter:
                alter_text: false
                ellipsis: true
                html: false
                make_link: false
                strip_tags: false
                trim: false
                word_boundary: true
              empty_zero: false
              field: name
              hide_empty: false
              id: name
              table: entity_test
              plugin_id: standard
              entity_type: entity_test
              entity_field: name
    

    3. Add multiple fields:

      view.view.my_view:
        setDisplayOption:
          -
            display_id: default
            option: fields
            item: my_field_id
            settings:
               alter:
                  alter_text: false
                  ellipsis: true
                  html: false
                  make_link: false
                  strip_tags: false
                  trim: false
                  word_boundary: true
                empty_zero: false
                field: my_field_id
                hide_empty: false
                id: my_field_id
                table: entity_test
                plugin_id: standard
                entity_type: entity_test
                entity_field: my_field_id
          -
            display_id: default
            option: fields
            item: my_another_field_id
            settings:
               alter:
                  alter_text: false
                  ellipsis: true
                  html: false
                  make_link: false
                  strip_tags: false
                  trim: false
                  word_boundary: true
                empty_zero: false
                field: my_another_field_id
                hide_empty: false
                id: my_another_field_id
                table: entity_test
                plugin_id: standard
                entity_type: entity_test
                entity_field: my_another_field_id
    
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev
Production build 0.71.5 2024