diff --git a/js/layout-paragraphs-builder.js b/js/layout-paragraphs-builder.js index 1d478155a5e70bc82448ed8fad27740dccf44bde..fcfaf4793290108806986c655f9940d73988c495 100644 --- a/js/layout-paragraphs-builder.js +++ b/js/layout-paragraphs-builder.js @@ -1103,23 +1103,7 @@ * @return {LPBuilder} The LPBuilder instance. */ on(type, fn) { - if (!this._events[type]) { - this._events[type] = [fn]; - } else { - this._events[type].push(fn); - } - return this; - } - - /** - * Add an event listener to fire only once. - * @param {string} type The event type. - * @param {function} fn The callback function. - * @return {LPBuilder} The LPBuilder instance. - */ - once(type, fn) { - fn._once = true; // thing.off(fn) still works! - this.on(type, fn); + this.$element.on(`lpb:${type}.lp-builder`, fn); return this; } @@ -1130,37 +1114,20 @@ * @return {LPBuilder} The LPBuilder instance. */ off(type = false, fn = false) { - if (type && !fn) { - delete this._events[type]; - } else if (!type && !fn) { - Object.keys(this._events).forEach((key) => { - delete this._events[key]; - }); - } else { - const et = this._events[type]; - if (!et) { - return this; - } - et.splice(et.indexOf(fn), 1); - } + this.$element.off(`lpb:${type}.lp-builder`, fn); return this; } /** * Emit an event listener. - * @param {*} type The event type. - * @return {array} An array of returned results from listeners. + * @param {array} args An array of arguments. + * @return {LPBuilder} The LPBuilder instance. */ emit(...args) { const type = args.shift(); - const et = (this._events[type] || []).slice(0); - return et.map((listener) => { - const val = listener.apply(this, args); - if (listener._once) { - this.off(type, listener); - } - return val; - }); + args.unshift(this); + this.$element.trigger(`lpb:${type}.lp-builder`, args); + return this; } } // End LPBuilder class. diff --git a/src/Form/LayoutParagraphsComponentAddForm.php b/src/Form/LayoutParagraphsComponentAddForm.php index 1fb578bad5ae1a08a5e689c69a9903ba9b30564c..d848fae88b4390f19d9dd8f032b51e6e3b8d4b85 100644 --- a/src/Form/LayoutParagraphsComponentAddForm.php +++ b/src/Form/LayoutParagraphsComponentAddForm.php @@ -74,7 +74,7 @@ class LayoutParagraphsComponentAddForm extends LayoutParagraphsComponentFormBase } $response->addCommand(new LayoutParagraphsBuilderInvokeHookCommand( - 'updateComponent', + 'component:insert', [ 'layoutId' => $this->layoutParagraphsLayout->id(), 'componentUuid' => $uuid, diff --git a/src/Form/LayoutParagraphsComponentEditForm.php b/src/Form/LayoutParagraphsComponentEditForm.php index 457afe6b79d51633984c73a85b31a552935fb78e..36db6a6181dee2ee0e7f86a065006bf5e4499993 100644 --- a/src/Form/LayoutParagraphsComponentEditForm.php +++ b/src/Form/LayoutParagraphsComponentEditForm.php @@ -55,7 +55,7 @@ class LayoutParagraphsComponentEditForm extends LayoutParagraphsComponentFormBas $response = new AjaxResponse(); $response->addCommand(new ReplaceCommand("[data-uuid={$uuid}]", $rendered_item)); $response->addCommand(new LayoutParagraphsBuilderInvokeHookCommand( - 'updateComponent', + 'component:update', [ 'layoutId' => $this->layoutParagraphsLayout->id(), 'componentUuid' => $uuid,