silverstripe-cms
silverstripe-cms copied to clipboard
Disable the Publish button if there is nothing to publish
Experience shows that users expect onBefore|AfterPublish
to be called when they hit the Publish
Button.
This doesn't happen, because there is nothing to publish when no changes are made. It would add value to disable the publish button unless there are changes to publish.
I've confirmed that Verioned->publishSingle()
does NOT call $owner->invokeWithExtensions('onBeforePublish');
when no changes need to be published (in SS4). Both "safe draft" and "publish" buttons are clickable regardless of any changes, but they are highlighted green when changes are detected. We could disable the buttons altogether, but I'm not confident enough in our change detection to do that just yet (e.g. TinyMCE needs a newline inserted in order to trigger change detection, doesn't trigger on any keypress).
Keen to get @clarkepaul UX feedback on this.
I think it would be good to disable the buttons but only if we are certain that our change detection is working every time for every scenario. That would be the most frustrating thing to have changes that you can't save or publish because we don't allow it.
The way it is designed is to give the actions more of a disabled look but not too much to make users think they can't click it again.
@Firesphere Can you add some more detail on the context of this issue here? Did you expect the extension to have an effect on publish, even though core didn't think a publish needed to happen?
Can we, perhaps, add a "onAfterSkippedPublish" just like we doe for DataObject::write()
?
Can you add some more detail on the context of this issue here? Did you expect the extension to have an effect on publish, even though core didn't think a publish needed to happen?
This was discussed in the CMS-users channel in the users Slack. Several developers found it confusing that when clicking the publish button (regardless of it's state) did not consistently invoke onBefore/After publish.
@Firesphere Do you want to send a PR for onAfterSkippedPublish
?
I can have a look at it, sure.
Just to add another thought on this - I don't think that disabling the publish/save buttons is a good idea even if our change detection is good because there are instances where you might want to force a publish/save event even if the current page has no explicit changes... perhaps you need to force a static publish action or some other onAfterSave hook that's needed
Yeah ... change detections could be a bit difficult here. The current page might not have any change to publish, but their could be related owned objects that do. Unless we have a full proof way of communicating back to the UI to decide if we should disable the button, disabling the button could be difficult.
Should point out that the publish button doesn't currently use its "dirty" state when a child object has draft changes. e.g.: You edit a form field on a UserForm page, save your changes and go back the main page. The "Publish" button comes back with it's green border (as opposed to the green background when its dirty).