From ee4369f9723a10d1f78838e904cde83448eb825a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 11 Oct 2019 14:41:05 -0400 Subject: [PATCH] Hook that allows custom logic before saving the composer --- .../discourse/models/composer.js.es6 | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 9ba0afe0aa0..5f13fb0940d 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -744,15 +744,22 @@ const Composer = RestModel.extend({ return false; }, - save(opts) { - if (!this.cantSubmitPost) { - // change category may result in some effect for topic featured link - if (!this.canEditTopicFeaturedLink) { - this.set("featuredLink", null); - } + // Overwrite to implement custom logic + beforeSave() { + return Ember.RSVP.Promise.resolve(); + }, - return this.editingPost ? this.editPost(opts) : this.createPost(opts); - } + save(opts) { + return this.beforeSave().then(() => { + if (!this.cantSubmitPost) { + // change category may result in some effect for topic featured link + if (!this.canEditTopicFeaturedLink) { + this.set("featuredLink", null); + } + + return this.editingPost ? this.editPost(opts) : this.createPost(opts); + } + }); }, clearState() {