From 0ae69429b5c64fa1c6e06af6b79aaa4a6e72d175 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 16 Aug 2022 09:29:08 -0600 Subject: [PATCH] Fix CustomFilterHeader did not work properly Some transformations were not correctly handled, and events were therefor not bound --- .../Headers/CustomFilterHeader.ts | 11 +++++++--- .../Widget/Nextmatch/Customfilter.php | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/api/js/etemplate/Et2Nextmatch/Headers/CustomFilterHeader.ts b/api/js/etemplate/Et2Nextmatch/Headers/CustomFilterHeader.ts index c0cb48c62e..e2c2e67743 100644 --- a/api/js/etemplate/Et2Nextmatch/Headers/CustomFilterHeader.ts +++ b/api/js/etemplate/Et2Nextmatch/Headers/CustomFilterHeader.ts @@ -43,13 +43,15 @@ export class Et2CustomFilterHeader extends FilterMixin(Et2InputWidget(LitElement { super.transformAttributes(attrs); - switch(attrs.widgetType) + let widgetType = this.getArrayMgr("modifications").getEntry(this.id)?.widgetType || attrs.widgetType || ""; + + switch(widgetType) { case "link-entry": this.widgetType = 'et2-nextmatch-header-entry'; break; default: - this.widgetType = attrs.widgetType; + this.widgetType = widgetType; // Prefer webcomponent, if legacy type was sent if(window.customElements.get("et2-" + this.widgetType)) { @@ -90,7 +92,10 @@ export class Et2CustomFilterHeader extends FilterMixin(Et2InputWidget(LitElement set value(new_value) { - this.filter_node.value = new_value; + if(this.filter_node) + { + this.filter_node.value = new_value; + } } } diff --git a/api/src/Etemplate/Widget/Nextmatch/Customfilter.php b/api/src/Etemplate/Widget/Nextmatch/Customfilter.php index ddc3837363..558bd6f7d6 100644 --- a/api/src/Etemplate/Widget/Nextmatch/Customfilter.php +++ b/api/src/Etemplate/Widget/Nextmatch/Customfilter.php @@ -31,22 +31,31 @@ class Customfilter extends Widget\Transformer */ public function beforeSendToClient($cname, array $expand=null) { + parent::beforeSendToClient($cname, $expand); switch($this->attrs['type']) { case "link-entry": self::$transformation['type'] = $this->attrs['type'] = 'et2-nextmatch-header-entry'; break; default: - list($type) = explode('-',$this->attrs['type']); + list($type) = explode('-', $this->attrs['type']); if($type == 'select') { if(in_array($this->attrs['type'], Widget\Select::$cached_types)) { $widget_type = $this->attrs['type']; } - $this->attrs['type'] = 'et2-nextmatch-header-custom'; } - self::$transformation['type'] = $this->attrs['type']; + else + { + // Run the new widget type's beforeSendToClient + $expanded_child = self::factory($this->attrs['type'], false, $this->id); + $expanded_child->id = $this->id; + $expanded_child->type = $this->attrs['type']; + $expanded_child->run('beforeSendToClient', array($cname, $expand)); + $widget_type = $expanded_child->attrs['type']; + } + $this->attrs['type'] = 'et2-nextmatch-header-custom'; } $form_name = self::form_name($cname, $this->id, $expand); @@ -55,9 +64,8 @@ class Customfilter extends Widget\Transformer self::setElementAttribute($form_name, 'type', $this->attrs['type']); if($widget_type) { - self::setElementAttribute($form_name, 'widget_type', $widget_type); + self::setElementAttribute($form_name, 'widgetType', $widget_type); } - parent::beforeSendToClient($cname, $expand); } @@ -80,4 +88,6 @@ class Customfilter extends Widget\Transformer $valid = $value ? $value : null; } } -Widget::registerWidget(__NAMESPACE__.'\\Customfilter', array('nextmatch-customfilter')); \ No newline at end of file + +Widget::registerWidget(__NAMESPACE__ . '\\Customfilter', array('nextmatch-customfilter', + 'et2-nextmatch-header-custom')); \ No newline at end of file