Problem/Motivation
While #3303127: Determine which core config entity methods should be config actions 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.
Therefore the config action plugin is needed that will help to update the view. One of the most common task is setting display option (display is a view display like default, page, block, entity reference, etc.; option is fields, filters, pager, etc.).
This task will be focused on config action that allows to add/update fields, filters, pagers. See documentation and example usage in #3305859-21: Add config actions for views.
Proposed resolution
- Create a config action
view:setDisplayOption. - Two methods in View entity class exposed as action methods:
addDisplayandduplicateDisplayAsType.
Remaining tasks
Implement.
User interface changes
None.
Introduced terminology
None.
API changes
New config actions.
Data model changes
None.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | 3305859-views-config-actions-30.patch | 15.39 KB | a.dmitriiev |
| #29 | 3305859-nr-bot.txt | 103 bytes | needs-review-queue-bot |
| #28 | 3305859-views-config-actions.patch | 15.27 KB | a.dmitriiev |
| #13 | 3305859-nr-bot.txt | 3.79 KB | needs-review-queue-bot |
| #10 | 3305859-views-config-actions.patch | 10.76 KB | a.dmitriiev |
Issue fork drupal-3305859
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Issue fork distributions_recipes-3305859
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nedjoA couple of sample diffs run from the root of a Drupal core repo:
Comment #4
thejimbirch commentedComment #5
a.dmitriiev commentedShould this issue be moved to Drupal project?
Comment #6
a.dmitriiev commentedComment #7
a.dmitriiev commentedComment #9
a.dmitriiev commentedUploading 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.
WRONG PATCH
Comment #10
a.dmitriiev commentedComment #11
a.dmitriiev commentedThe 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.override(optional, default FALSE) - allows to override the display option (make it only for the current display)Example usage:
2.
addItemToDisplayOptionallows to add the item to views display option. The difference fromsetDisplayOptionis 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:item(required) - for the name of the item to add.allow_update(optional, default to FALSE) - if it is set to TRUE the existing item will be updated, if set to FALSE - the exception will be thrown with message that item already exists.Example usage:
3.
removeItemFromDisplayOptionallows to remove the item from views display option.Parameters:
The same as for
addItemToDisplayOption, minus onesettingsas it is not needed for item that is removed.Example usage:
Comment #12
a.dmitriiev commentedI have also exposed 2 methods from view entity class:
addDisplayandduplicateDisplayAsTypeas Action Methods to use as config actions.Comment #13
needs-review-queue-bot commentedThe 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.
Comment #14
a.dmitriiev commentedThere are some tests with blocks that are failing, I assume not related to the tests form MR.
Comment #15
nmudgal commentedLooks like it was just a fluke. Rerunning the pipeline resolved the failing test issue.
Comment #16
asawari commentedHi,
Please add steps to reproduce to test.
Comment #17
a.dmitriiev commentedFor 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.
Comment #18
penyaskitoThis is a Drupal CMS stable release blocker for the search filters recipe #3488715: Add recipe for search facets, 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.
Comment #19
phenaproximaThis 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.
Comment #20
phenaproximaReviewed. 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.
Comment #21
a.dmitriiev commentedI have removed config action that removes display option items from MR. I have also combined
setDisplayOptionwithaddItemToDisplayOptionconfig actions. Here is the updated usage documentation:setDisplayOptionconfig 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
2. Add a field to a view:
3. Add multiple fields:
Comment #22
a.dmitriiev commentedComment #23
smustgrave commentedThis is looking real good
Can issue summary be updated with what's being added. Title is pretty vague.
Also probably need a CR now for the new actions.
Comment #24
a.dmitriiev commentedComment #25
a.dmitriiev commentedI have updated the description of the issue. Are there any examples of how change record for new config action should look like? What should be included? Would content of comment https://www.drupal.org/project/drupal/issues/3305859#comment-15896386 be enough?
Comment #26
thejimbirch commentedComment #21 is a great start for the change record. In addition, we should also document that you added and how to use
addDisplayandduplicateDisplayAsType.Here is a past example of a change record for a new config action.
https://www.drupal.org/node/3481714
Comment #27
a.dmitriiev commentedChange record was added. I have also added the ability to place field/filter after or before defined field/filter for more flexibility
Comment #28
a.dmitriiev commentedFailed test seems to be unrelated to the changes from this issue.
Attaching also patch for using in composer based projects.
Comment #29
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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.
Comment #30
a.dmitriiev commentedI have rebased the MR on latest 11.x changes.
Uploading re-rolled patch
Comment #31
smustgrave commentedSorry to be that guy be even a task can we use the default template.
Comment #32
thejimbirch commentedComment #35
liam morlandI have rebased the merge request and put the issue summary into the template.
Comment #36
smustgrave commentedMR appears to have problems.