silverstripe / silverstripe-widgets

Widgets subsystem for Silverstripe CMS
http://silverstripe.org
BSD 3-Clause "New" or "Revised" License
38 stars 55 forks source link

Duplicating a page with Widgets doesn't assign new SideBarID #190

Open jfullerton opened 2 years ago

jfullerton commented 2 years ago

This was supposedly fixed before in #58 and I think #188 might also be referencing this issue.

Expected Behavior

Duplicating a page should also duplicate the WidgetArea and Widgets in it, and the resulting new page be assigned a SideBarID corresponding to the duplicated WidgetArea.

Actual Behavior

Duplicating a page does create copies of the original WidgetArea and Widgets but the resulting page's SideBarID still points to the original page's WidgetArea.

Steps to Reproduce the Problem

  1. Create a new Silverstripe project
    composer create-project silverstripe/installer <project-name>
  2. Add Widgets module and Blog module (for default widgets)
    composer require silverstripe/widgets silverstripe/blog
  3. Add WidgetPageExtension to Page in config
    Page:
    extensions:
      - SilverStripe\Widgets\Extensions\WidgetPageExtension
  4. Choose a page in the CMS, add a widget, Save & Publish.
  5. Duplicate the page, rename the widget on the new page, Save & Publish.
  6. The name of the widget has changed on the original page.
  7. Looking in the database, both the Widget and WidgetArea have been duplicated, but the duplicated page still has the original page's SideBarID.

Specifications

dhensby commented 2 years ago

Is this all pages or just child pages? It looks like from the Page extension that maybe there could be a problem if InheritSideBar is true... (which is default) and the page is a child page... I can't really see immediately why this would happen on parent pages, though...


edit: It definitely looks like this feature could use some test coverage ;)

jfullerton commented 2 years ago

Yeah, this is happening on all pages, I tried both top level pages and child pages. Unchecking "Inherit Sidebar From Parent" doesn't change the result.

Stepping through the onBeforeDuplicate function on WidgetPageExtension, everything seems fine.

https://github.com/silverstripe/silverstripe-widgets/blob/5aca443a7c9abb8abe9e71be0d13b69085f417f1/src/Extensions/WidgetPageExtension.php#L69-L85

The values being assigned were all correct and new records were being created. Even the SIdeBarID assigned on this line was also correct, but once the function returns, it apparently doesn't stick or is overwritten?

https://github.com/silverstripe/silverstripe-widgets/blob/5aca443a7c9abb8abe9e71be0d13b69085f417f1/src/Extensions/WidgetPageExtension.php#L81