From 834e4f7824fc1778e75a57f3ce1151335285c8ea Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 23 Apr 2024 09:45:30 +0200 Subject: [PATCH] fix changing entry-type (with automatic submit) did not change custom-field tabs and displayed fields --- .../etemplate/et2_extension_customfields.ts | 8 ----- api/src/Etemplate/Widget/Tabbox.php | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/api/js/etemplate/et2_extension_customfields.ts b/api/js/etemplate/et2_extension_customfields.ts index d6389a5696..4bae9442f8 100644 --- a/api/js/etemplate/et2_extension_customfields.ts +++ b/api/js/etemplate/et2_extension_customfields.ts @@ -151,12 +151,8 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac } if(this.options.type_filter) { - const already_filtered = !jQuery.isEmptyObject(this.options.fields); for(let field_name in this.options.customfields) { - // Already excluded? - if(already_filtered && !this.options.fields[field_name]) continue; - if(!this.options.customfields[field_name].type2 || this.options.customfields[field_name].type2.length == 0 || this.options.customfields[field_name].type2 == '0') { @@ -237,10 +233,6 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac this.options.fields[field_name] = default_tab[1] !== '-private'; } } - else if (this.options.tab && this.options.customfields[field_name].tab === this.options.tab) - { - this.options.fields[field_name] = true; - } } } diff --git a/api/src/Etemplate/Widget/Tabbox.php b/api/src/Etemplate/Widget/Tabbox.php index 011d85fcd8..f1e758a669 100644 --- a/api/src/Etemplate/Widget/Tabbox.php +++ b/api/src/Etemplate/Widget/Tabbox.php @@ -47,7 +47,7 @@ class Tabbox extends Etemplate\Widget * * @param string|callable $method_name or function($cname, $expand, $widget) * @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand! - * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children + * @param boolean $respect_disabled false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children */ public function run($method_name, $params=array(''), $respect_disabled=false) { @@ -141,9 +141,9 @@ class Tabbox extends Etemplate\Widget * Method called before eT2 request is sent to client * * @param string $cname - * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' + * @param array|null $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' */ - public function beforeSendToClient($cname, array $expand=null) + public function beforeSendToClient($cname, ?array $expand=null) { [$app] = explode('.', self::$request->template['name']); // no need to run if we have no custom fields @@ -163,10 +163,10 @@ class Tabbox extends Etemplate\Widget { $prepend = in_array($prepend, ['true', '1']); } - // is adding of CFs disabled --> exit - if (!empty($this->attrs['cfDisabled'])) + // is adding of CFs disabled --> unset them all + if (!empty($this->attrs['cfDisabled']) && $this->attrs['cfDisabled'] !== 'false') { - return; + $cfs = []; } // check if template still contains a legacy customfield tab @@ -230,27 +230,30 @@ class Tabbox extends Etemplate\Widget ]; } } + // filter out previously added custom-field tabs, as they might change due to cfTypeFilter + if (($extra_tabs =& self::getElementAttribute($this->id, 'extraTabs'))) + { + $extra_tabs = array_filter($extra_tabs, static function($tab) + { + return !preg_match('/^cf-(default(-(non-)?private)?|tab\d+)$/', $tab['id']); + }); + } if ($tabs || $default_tab || $private_tab) { // pass given cfTypeFilter attribute via content to all customfields widgets (set in api.cf-tab template) - if ($type_filter) + if (($type_filter=implode(',', $type_filter))) { $content = self::$request->content; - $content['cfTypeFilter'] = implode(',', $type_filter); + $content['cfTypeFilter'] = $type_filter; self::$request->content = $content; } // pass cfExclude attribute via content to all customfields widgets (set in api.cf-tab template) - if ($exclude) + if (($exclude=implode(',', $exclude))) { $content = self::$request->content; - $content['cfExclude'] = implode(',', $exclude); + $content['cfExclude'] = $exclude; self::$request->content = $content; } - // we must not add tabs again! - if (!empty(self::$response)) - { - return; - } // addTabs is default false (= replace tabs), we need a default of true $add_tabs =& self::setElementAttribute($this->id, 'addTabs', null); if (!isset($add_tabs)) $add_tabs = true; @@ -260,7 +263,7 @@ class Tabbox extends Etemplate\Widget $extra_tabs = array_merge($extra_tabs ?? [], $default_tab, $private_tab, array_values($tabs)); // if we have no explicit default cf widget/tab, we need to call customfields::beforeSendToClient() to pass cfs to client-side - $cfs = new Customfields(''); + $cfs = new Customfields(""); $cfs->beforeSendToClient($cname, $expand); } }