This would be a small usability improvement. Right now, when you add a REST export display, you immediately get an error saying a path hasn't been specified. You then need to manually specify a path, and it's not clear as an end user a) where that is, and b) what you'd put in there. The flow is kind of like this:

Immediately get an error, scroll 2+ pages down to see it
Now that you've read the error, scroll back up
Scan all around the page looking for the section.
Finally find it, but not sure what to put

Suggestion would be that if the View already has a Page display (such as the Frontpage view), just carry over that path so the user never gets this error in the first place. This would mirror how entities work (what you get on node/1 depends on what headers you sent). And in my testing, if you specify /node as the REST export path of the Frontage view, and shoot text/html you get back HTML, if you shoot application/json+hal, you get back JSON, so it seems to work as expected.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Category: Task » Feature request

If your rest display should work like a page display use the clone display as rest export functionality.

People will disagree with that statement, but I really think this is a feature request not a task. Hard coding everything is a bad behavior,
given that in order to make the path usefull really working you basically want to have the same filters, fields, contextual filters and access configuration aka clone.

dawehner’s picture

An alternative, which at least improve things, would be to automatically open the path modal when you add a new rest display.

dawehner’s picture

FileSize
2.39 KB
clemens.tolboom’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: rest-2302615.patch, failed testing.

Helpermedia’s picture

Patch is re-rolled. It's not working as expected, cause is probably:

$view->addFormToStack('display', $display_id, 'menu');

The path modal does not come up as expected according to #2

clemens.tolboom’s picture

This does not seem trivial according to @dawehner@irc

Checking addFormToStack

  /**
   * Add another form to the stack; clicking 'apply' will go to this form
   * rather than closing the ajax popup.
   */
  public function addFormToStack($key, $display_id, $type, $id = NULL, $top = FALSE, $rebuild_keys = FALSE) {

it suggests we have an overlay but that's not true. We just clicked the 'Add REST export' button.

dawehner’s picture

FileSize
6.48 KB

Worked on it, total different approach.

clemens.tolboom’s picture

Status: Needs work » Needs review

Nice rephrase solution. Works as described in #2

This solved the required path for (rest export) path displays by adding a dialog but what if two or more fields are required? The patch from #3 suggested we can add multiple items to the form stack.

I like the solution of #8 but let @webchick RTBC

Maybe @Helpermedia can do another review?

Wim Leers’s picture

Title: Default REST Export path setting to the Page path setting if a Page display exists » REST views: Default REST Export path setting to the Page path setting if a Page display exists
Wim Leers’s picture

@dawehner asked me to review this, but I don't feel qualified to review this. I think @tim.plunkett would be a better candidate. (None of this even touches the REST module btw: 0 changes in \Drupal\rest\Plugin\views\display\RestExport.)

clemens.tolboom’s picture

Title: REST views: Default REST Export path setting to the Page path setting if a Page display exists » Show path dialog when adding a path based display
Version: 8.0.x-dev » 8.2.x-dev
Component: rest.module » views.module

@wim-leers changing the title doesn't fix the 0 rest related changes ;-)

This patch pops-up the path dialog for any page based display.

dawehner’s picture

@Wim Leers
Well, the reason to review that was related with the javascript additions ...

dawehner’s picture

This patch pops-up the path dialog for any page based display.

Don't we want that all the time? Seems like a super reasonable assumptions for me at least.

clemens.tolboom’s picture

Patch needed a re-roll. I took a3fd4d0f8cf5c5c as a start.

Adding a new (path based) display does not trigger the path dialogue so needs work too.

vbouchet’s picture

Having this improvement may fix a real bug.

dawehner’s picture

Just some quick nitpick review :)

  1. +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
    @@ -527,7 +527,8 @@ public function getAlteredRouteNames() {
        */
    -  public function remove() {
    +  public function remove()
    +  {
    

    unrelated change

  2. +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
    @@ -536,4 +537,8 @@ public function remove() {
     
    +  public function mainDisplaySection() {
    +    return 'path';
    +  }
    

    Let's put {@inheritdoc} on there

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.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.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.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.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.

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.

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs subsystem maintainer review

Curious what the subsystem maintainer things? Also some changes were requested in last comment

sahil.goyal’s picture

i'm rerolling the patch as seen that #15 was too old so it cannot apply to the current version 10.1.x, addresses the comment #17. And attaching the reroll file for the same.

_utsavsharma’s picture

Fixed #32.
Please review.

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.