If you have multiple displays, and one page display has overridden fields or style plugin settings, and you want to create a block display that has those exact settings, you have to manually rebuild it.

The idea is that you could choose the new display plugin while cloning, along with a warning saying that all display settings will be unconditionally thrown away. Some display plugins share similar setting names that mean different things, so there should be no attempt to translate those.

Comments

dawehner’s picture

I would really like to have this feature but it has to be clear for the user that the options which are special for this display (which are not that easy to detect) might be removed.

lukus’s picture

I agree this is a great idea. Perhaps a nice way of implementing this would be to offer a 'Clone as...' option, so the user's provided with a duplicate in the new display style which they can preview before saving.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new7.07 KB

This is a really rough first pass, just to demonstrate the idea.
I just duplicated the relevant code needed, ideally it could just be abstracted to work for both.

tim.plunkett’s picture

tim.plunkett’s picture

StatusFileSize
new1.54 KB

Chatted with @dereine about this, here's another idea. Much less code. Still doesn't fully work.

https://skitch.com/plnktt/8nwd9/fullcalendar-content-d7

tim.plunkett’s picture

Triggering the testbot.

korzh-nick’s picture

Thanks for the patch. I patched the version 7.x-3.3 - I cloned the page as a block. Clone title and filter settings are not working. More precisely cloned default.

tim.plunkett’s picture

Status: Needs review » Needs work

Yeah, this definitely doesn't work yet.

dawehner’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.x-dev
Component: Code » views_ui.module
Status: Needs work » Needs review
Issue tags: +VDC
StatusFileSize
new3.44 KB

Let's implement that for Drupal 8.

dawehner’s picture

StatusFileSize
new4.6 KB
new3.29 KB

Got it working for overridden values as well.

damiankloip’s picture

Nice, that's the main issue I found. I'll test this in the morning!

damiankloip’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.phpundefined
@@ -766,6 +781,31 @@ public function submitDisplayAdd($form, &$form_state) {
+    $displays[$new_display_id]['id'] = $new_display_id;

We should probably unset (maybe?) or set the display_title to something too? As at the moment, wont this just inherit whatever the display being cloned from has? So if you cloned 'Page 7' your clone display title would also be 'Page 7'.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new4.8 KB
new1.9 KB

Yeah you are right, what about something like that?

Status: Needs review » Needs work

The last submitted patch, drupal-1401778-13.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB
new5.52 KB

Rewrote that cloning part to better work as expected and added a test.

damiankloip’s picture

+++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.phpundefined
@@ -788,14 +788,17 @@ public function submitCloneDisplayAsType($form, &$form_state) {
+    $display_clone = $displays[$display_id];
+    unset($display_clone['display_title']);
 
-    // Copy the display options and plugin but leave the title left.
-    $displays[$new_display_id]['display_options'] = $displays[$display_id]['display_options'];
-    $displays[$new_display_id]['display_plugin'] = $displays[$display_id]['display_plugin'];
+    $displays[$new_display_id] += $display_clone;

That's a much cleaner way to merge the options, I was going to suggest something along those lines :) Like that.

This patch is looking good now. It is working as expected with the overridden options, as well as the quibble with the title.

I wont RTBC just yet, we should get a couple more people to test first.

Status: Needs review » Needs work

The last submitted patch, drupal-1401778-15.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new2.22 KB
new0 bytes

The tests were assertingEqual for the title, but asserting on the display plugin object and not the display_title, also the change in #15 for the merging (+=) doesn't do a deep merge, so I've added NestedArray::mergeDeep instead, we can use this (which I'm ok with) or switch back to the previous method of doing this.

Also, probably out of scope for here, but I think the regular submitDisplayDuplicate method doesn't handle the title properly, if you have a page and you clone the title will still be 'Page'.

damiankloip’s picture

StatusFileSize
new5.24 KB

Oops! a real patch would be good. Thanks tim.

dawehner’s picture

This change looks fine, so do you agree this is RTBC?

damiankloip’s picture

I am happy with this now, but I did the last fix. So maybe Tim should do the honours?!

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

I'd like to review this but it's Christmas so if you don't mind waiting until Wednesday...

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
StatusFileSize
new5.41 KB
new1.62 KB

This still doesn't actually work. Taking a page display and cloning as a block indeed adds a display called block_1, but it's still actually a page display plugin.

I've added some failing assertions, I didn't try to debug why.

dawehner’s picture

StatusFileSize
new5.48 KB
new1.09 KB

uggggggh thanks for opening these eyes ... I swear this worked in the first versions of the patch!

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Ah, that was a good fix.

It works now, and passes tests.

catch’s picture

Issue tags: -VDC

#24: drupal-1401778-24.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work
Issue tags: +VDC

The last submitted patch, drupal-1401778-24.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new2.02 KB
new5.47 KB

We need to get() that stuff instead.

Status: Needs review » Needs work
Issue tags: -VDC

The last submitted patch, 1401778-28.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
Issue tags: +VDC

#28: 1401778-28.patch queued for re-testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for bringing this back to the table!
Back to RTBC once it's green.

tim.plunkett’s picture

StatusFileSize
new2.24 KB
new5.46 KB
catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks good. Committed/pushed to 8.x

rogical’s picture

Is that possible to backport to D7?

dawehner’s picture

Project: Drupal core » Views (for Drupal 7)
Version: 8.x-dev » 7.x-3.x-dev
Component: views_ui.module » User interface
Status: Fixed » Patch (to be ported)
FranCarstens’s picture

Issue summary: View changes

Was this ever ported?

zalak.addweb’s picture

Issue tags: +views
3dnathaniel’s picture

subscribing for d7 port

alex.bukach’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new2.46 KB

Status: Needs review » Needs work

The last submitted patch, 39: views-clone-display-as-1401778-39-D7.patch, failed testing. View results

alex.bukach’s picture

Status: Needs work » Needs review
StatusFileSize
new2.69 KB
weka’s picture

Brilliant, thanks Alex.
Patch in #41 seems to be working fine with latest 7.x-3.20+0-dev.

davidkp’s picture

Brilliant #41 works perfect! Thanks

alfthecat’s picture

This patch is the time-saver of the year! Works brilliantly against the latest dev, views just got even better. Thanks everyone!

damienmckenna’s picture

Nice work everyone.

Has anyone tested to see if there are problems cloning a display and carrying along settings which are not appropriate for the new display type? For example, if you clone a page and make it a block, do errors show up related to the original page display's options? Are the old settings exported with the new display?

alfthecat’s picture

For my part, I've been cloning at least a dozen blocks to panels content panes and not a single error. Neither did settings get lost that are shared between source and clone (such as table style config like sorting options, css row classes, etc). I've also cloned a page to a views data export display and no problems at all.

Also aplied the patch against latest stable version, and everything works fine too.

This is indeed really great work, and to much delight.

phily’s picture

Patch #41 works for me tested using Drupal 7.70 with patch applied to Views 7.x-3.24
Cloning a page (with menu parameters) to a block triggered no errors so far, all settings where cloned perfectly (except unrelevant like menu) and both page and block run OK.
Thanks to all for your efforts.

nwom’s picture

Status: Needs review » Reviewed & tested by the community

#41 worked great. Setting as RTBC, since others have said it works perfectly as well. Thanks for everyone's work on this!

jasonaaronwood’s picture

Applying the patch from #41 gives me the error:

At line:1 char:7
+ patch < views-clone-display-as-1401778-41-D7.patch
+       ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported
damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you all!

damienmckenna’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.