Problem/Motivation

The REST export (\Drupal\rest\Plugin\views\display\RestExport) ViewsDisplay plugin allows paths to be configured for displays, but does not allow menu entries. While menu entries may not make sense for JSON serialization, there are use cases for other types.

For example, https://www.drupal.org/project/csv_serialization and https://www.drupal.org/project/xls_serialization allow users to create a View and have it create a CSV or XLS file. A user may want to make these available as a menu entry (eg, a menu of all of the XLS reports that can be generated from a site). Right now, you can add the path manually to a menu, but this means path changes need to be updated in multiple places and can cause quirks with permission changes made in views. You can also make a similar case for XML exports (I have had clients where we have done lots of manually trading XML back and forth).

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpdonadio created an issue. See original summary.

mpdonadio’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
3.6 KB

Untested, but mirroring what \Drupal\views\Plugin\views\display\Page does. Just want to see what explodes.

May also want contextual links?

Status: Needs review » Needs work

The last submitted patch, 2: 2848971-02.patch, failed testing.

shadcn’s picture

We had a similar use case in a recent project. So this make sense.

+++ b/core/modules/rest/src/Plugin/views/display/RestExport.php
@@ -94,6 +96,13 @@ class RestExport extends PathPluginBase implements ResponseDisplayPluginInterfac
@@ -110,12 +119,15 @@ class RestExport extends PathPluginBase implements ResponseDisplayPluginInterfac

Missing defineOptions, buildOptionsForm et al. Looks like a lot of these are encapsulated inside Page plugin.

Maybe extract these to a PagePluginPage?

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
33.83 KB
30.23 KB

Can't find what I am missing to make the menu option appear.

mpdonadio’s picture

Issue tags: +DrupalCampNJ2017

Status: Needs review » Needs work

The last submitted patch, 5: 2848971-05.patch, failed testing.

Wim Leers’s picture

Title: REST export (rest_export) ViewsDisplay plugin should allow menu paths » REST views: should allow menu paths (for serialization formats such as CSV or XLS)
Wim Leers’s picture

This is closely related to #2778569: REST views: Consider implementing `attachTo` method in `RestExport` display plugin, in that this too would allow for a better UX for views with CSV/XLS/… exports.

I think this is a similarly rare need that this also deserves minor priority.

Wim Leers’s picture

Pinged @mpdonadio.

mpdonadio’s picture

Issue tags: +Needs reroll

Still stuck on what the bug is in #5.

This will need a reroll for the array syntax change.

Wim Leers’s picture

Yay!

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
32.72 KB

Patch #5 no longer applies. Re-roll updating array syntax.

Status: Needs review » Needs work

The last submitted patch, 13: 2848971-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mpdonadio’s picture

Bot fail aside, I am at a loss why the menu option isn't appearing. I keep comparing the RestExport plugin against the page one and don't see what is missing.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

Status: Needs work » Needs review
FileSize
33.01 KB

Patch in #13 no longer applies. Re-rolled.

jofitz’s picture

Correct test failures and coding standards errors.

The last submitted patch, 17: 2848971-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Wim Leers’s picture

Nice!

But, sorry, I still don't see test coverage. Also, I'm not a Views maintainer. This will need a review from one of them. Keeping at NR for now. Please ping one of the Views maintainers for a review!

Wim Leers’s picture

Title: REST views: should allow menu paths (for serialization formats such as CSV or XLS) » REST views: change PathPluginBase so RestExport displays allow menu paths (for serialization formats such as CSV or XLS)
Component: rest.module » views.module

Better yet… let's move it to the Views module component to get a review.

This is making significant changes to PathPluginBase, which is definitely Views module material. Updating title to clarify that.

mpdonadio’s picture

This doesn't apply to 8.4.x anymore, so I can't check it on the site where I was running into this problem, but last time I tried a patch on this issue the menu path wasn't appearing on the config page for this display view. So, we definitely need a functional test to cover this.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Issue tags: +API-First Initiative
mpdonadio’s picture

OK, it turns out the menu option was hiding in the advanced tab...

First pass at a test. This fails because the menu entry for the REST display doesn't include the _format query. Not 100% sure why.

Probably want to update the test to do a proper simulation of adding the menu entry, but wanted to get this working first.

Status: Needs review » Needs work

The last submitted patch, 25: 2848971-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
52.38 KB
10.04 KB

This will be green and reviewable.

Status: Needs review » Needs work

The last submitted patch, 27: 2848971-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mpdonadio’s picture

Priority: Minor » Major

Well, the tests I ran were green :) Still would appreciate feedback on the patch while I look at the side effects from it.

Also tentatively raising to Major, as I think this will help mitigate #2937942: REST views: regression in 8.5.x: view with display using 'csv' format now returns a 406 response, need to add ?_format=csv to URL to make it work in the long run.

Wim Leers’s picture

This especially needs reviews from Views maintainers.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.