From 2552bea6a2a370e01673f9808d5dcd82b15b3631 Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 24 Oct 2024 21:25:20 +0200 Subject: [PATCH] change api\Etemplate\Widget::getElementAttribute($name,$attr) to NO longer return a reference, use setElementAttribute($name,$attr) if you need a reference --- api/src/Etemplate.php | 2 +- api/src/Etemplate/Widget.php | 21 +++++++++++-------- api/src/Etemplate/Widget/Customfields.php | 18 ++++++++-------- api/src/Etemplate/Widget/Select.php | 7 ++++--- api/src/Etemplate/Widget/Tabbox.php | 4 ++-- .../class.calendar_favorite_portlet.inc.php | 10 ++++----- filemanager/inc/class.filemanager_ui.inc.php | 2 +- .../class.importexport_widget_filter.inc.php | 2 +- 8 files changed, 35 insertions(+), 31 deletions(-) diff --git a/api/src/Etemplate.php b/api/src/Etemplate.php index fdffd37f24..5afd85eec6 100644 --- a/api/src/Etemplate.php +++ b/api/src/Etemplate.php @@ -644,7 +644,7 @@ class Etemplate extends Etemplate\Widget\Template * @return mixed reference to attribute, usually NULL * @deprecated use getElementAttribute($name, $attr) */ - public function &get_cell_attribute($name,$attr) + public function get_cell_attribute($name,$attr) { return self::getElementAttribute($name, $attr); } diff --git a/api/src/Etemplate/Widget.php b/api/src/Etemplate/Widget.php index 136e18025f..de4356beba 100644 --- a/api/src/Etemplate/Widget.php +++ b/api/src/Etemplate/Widget.php @@ -1075,14 +1075,15 @@ class Widget /** * Returns reference to an attribute in a named cell * - * Currently we always return a reference to an not set value, unless it was set before. - * We do not return a reference to the actual cell, as it get's contructed on client-side! + * We no longer return a reference to the attribute! + * + * If you need a reference, use: $attr =& setElementAttribute($name, $attr) * * @param string $name cell-name * @param string $attr attribute-name - * @return mixed reference to attribute, usually NULL + * @return mixed attribute, usually NULL */ - public function &getElementAttribute($name, $attr) + public function getElementAttribute($name, $attr) { //error_log(__METHOD__."('$name', '$attr')"); return self::$request->modifications[$name][$attr]; @@ -1098,7 +1099,7 @@ class Widget * @param mixed $val if not NULL sets attribute else returns it * @return reference to attribute */ - public static function &setElementAttribute($name,$attr,$val) + public static function &setElementAttribute($name,$attr,$val=null) { if (!isset(self::$request)) { @@ -1106,7 +1107,7 @@ class Widget } //error_log(__METHOD__."('$name', '$attr', ...) request=".get_class(self::$request).", response=".get_class(self::$response).function_backtrace()); $ref =& self::$request->modifications[$name][$attr]; - if(self::$request && self::$response) + if(self::$request && self::$response && isset($val)) { // In an AJAX response - automatically add self::$response->generic('assign',array( @@ -1119,8 +1120,10 @@ class Widget self::$request->unset_to_process(''); //error_log(__METHOD__."('$name', '$attr', ...) ".function_backtrace()); } - if (!is_null($val)) $ref = $val; - + if (isset($val)) + { + $ref = $val; + } //error_log(__METHOD__."('$name', '$attr', ".array2string($val).')'); return $ref; } @@ -1130,7 +1133,7 @@ class Widget * * @param string $name cell-name * @param boolean $disabled =true disable or enable a cell, default true=disable - * @return reference to attribute + * @return attribute */ public function disableElement($name,$disabled=True) { diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index d0daaddc4f..2824aaa625 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -104,10 +104,10 @@ class Customfields extends Transformer } else { - $app =& $this->getElementAttribute(self::GLOBAL_VALS, 'app'); - if($this->getElementAttribute($form_name, 'app')) + $app =& self::setElementAttribute(self::GLOBAL_VALS, 'app'); + if(self::getElementAttribute($form_name, 'app')) { - $app =& $this->getElementAttribute($form_name, 'app'); + $app =& self::setElementAttribute($form_name, 'app'); } else { @@ -116,15 +116,15 @@ class Customfields extends Transformer } } - if($this->getElementAttribute($form_name, 'customfields')) + if(self::getElementAttribute($form_name, 'customfields')) { - $customfields =& $this->getElementAttribute($form_name, 'customfields'); + $customfields =& self::setElementAttribute($form_name, 'customfields'); } elseif($app) { // Checking creates it even if it wasn't there unset(self::$request->modifications[$form_name]['customfields']); - $customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields'); + $customfields =& self::setElementAttribute(self::GLOBAL_VALS, 'customfields'); } if(!$app && !$customfields) @@ -484,13 +484,13 @@ class Customfields extends Transformer // if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find if (!$this->id) $content = array_merge($content, (array)$value_in); //error_log(__METHOD__."($cname, ...) form_name=$form_name, private={$this->attrs['private']}, value_in=".array2string($value_in)); - if($this->getElementAttribute($form_name, 'customfields')) + if(self::getElementAttribute($form_name, 'customfields')) { - $customfields =& $this->getElementAttribute($form_name, 'customfields'); + $customfields =& self::setElementAttribute($form_name, 'customfields'); } else { - $customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields'); + $customfields =& self::setElementAttribute(self::GLOBAL_VALS, 'customfields'); } if(is_array($value_in)) { diff --git a/api/src/Etemplate/Widget/Select.php b/api/src/Etemplate/Widget/Select.php index a57be3fe4d..500d3472cb 100644 --- a/api/src/Etemplate/Widget/Select.php +++ b/api/src/Etemplate/Widget/Select.php @@ -149,9 +149,10 @@ class Select extends Etemplate\Widget { $widget_type = substr($widget_type, 4); } - $multiple = $this->attrs['multiple'] || $this->getElementAttribute($form_name, 'multiple') || $this->getElementAttribute($form_name, 'rows') > 1; - $allowFreeEntries = $this->attrs['allowFreeEntries'] || $this->getElementAttribute($form_name, 'allowFreeEntries') || - $this->attrs['searchUrl'] || $this->getElementAttribute($form_name, 'searchUrl'); + $multiple = $this->attrs['multiple'] || self::getElementAttribute($form_name, 'multiple') || + self::getElementAttribute($form_name, 'rows') > 1; + $allowFreeEntries = $this->attrs['allowFreeEntries'] || self::getElementAttribute($form_name, 'allowFreeEntries') || + $this->attrs['searchUrl'] || self::getElementAttribute($form_name, 'searchUrl'); $ok = true; if (!$this->is_readonly($cname, $form_name)) diff --git a/api/src/Etemplate/Widget/Tabbox.php b/api/src/Etemplate/Widget/Tabbox.php index f1e758a669..cf92d27e5d 100644 --- a/api/src/Etemplate/Widget/Tabbox.php +++ b/api/src/Etemplate/Widget/Tabbox.php @@ -54,7 +54,7 @@ class Tabbox extends Etemplate\Widget $form_name = self::form_name($params[0], $this->id, $params[1]); // Make sure additional tabs are processed for any method - if(!($tabs =& self::getElementAttribute($form_name, 'extraTabs'))) + if(!($tabs =& self::setElementAttribute($form_name, 'extraTabs'))) { $tabs = $this->attrs['extraTabs']; } @@ -231,7 +231,7 @@ 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'))) + if (($extra_tabs =& self::setElementAttribute($this->id, 'extraTabs'))) { $extra_tabs = array_filter($extra_tabs, static function($tab) { diff --git a/calendar/inc/class.calendar_favorite_portlet.inc.php b/calendar/inc/class.calendar_favorite_portlet.inc.php index 44a32fd4f5..0556e04379 100644 --- a/calendar/inc/class.calendar_favorite_portlet.inc.php +++ b/calendar/inc/class.calendar_favorite_portlet.inc.php @@ -110,7 +110,7 @@ class calendar_favorite_portlet extends home_favorite_portlet $content = array(); $etemplate->read('calendar.planner'); $etemplate->set_dom_id($id); - $this->actions =& $etemplate->getElementAttribute('planner', 'actions'); + $this->actions =& $etemplate->setElementAttribute('planner', 'actions'); // Don't notify the calendar app of date changes $etemplate->setElementAttribute('planner','onchange',false); $ui->planner_view = $this->favorite['state']['planner_view']; @@ -120,7 +120,7 @@ class calendar_favorite_portlet extends home_favorite_portlet case 'weekN': $etemplate->read('calendar.view'); $etemplate->set_dom_id($id); - $this->actions =& $etemplate->getElementAttribute('view', 'actions'); + $this->actions =& $etemplate->setElementAttribute('view', 'actions'); $ui->month($this->favorite['state']['view'] == 'month' ? 0 : @@ -131,7 +131,7 @@ class calendar_favorite_portlet extends home_favorite_portlet case 'week': $etemplate->read('calendar.view'); $etemplate->set_dom_id($id); - $this->actions =& $etemplate->getElementAttribute('view', 'actions'); + $this->actions =& $etemplate->setElementAttribute('view', 'actions'); // Don't notify the calendar app of date changes $etemplate->setElementAttribute('view[0]','onchange',false); $ui->week(array(), $etemplate); @@ -143,7 +143,7 @@ class calendar_favorite_portlet extends home_favorite_portlet $days = $this->favorite['state']['days'] ? $this->favorite['state']['days'] : ( $this->favorite['state']['view'] == 'day' ? 1 : 4 ); - $this->actions =& $etemplate->getElementAttribute('view', 'actions'); + $this->actions =& $etemplate->setElementAttribute('view', 'actions'); $ui->week($days, $etemplate); return; } @@ -262,4 +262,4 @@ class calendar_favorite_portlet extends home_favorite_portlet { return 'et2-portlet-calendar'; } -} +} \ No newline at end of file diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index d718745cf9..1da5603a82 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -1623,7 +1623,7 @@ class filemanager_ui // add to existing tabs in template $tpl->setElementAttribute('tabs', 'add_tabs', true); - $tabs =& $tpl->getElementAttribute('tabs', 'extraTabs'); + $tabs =& $tpl->setElementAttribute('tabs', 'extraTabs'); if (true) $tabs = array(); foreach(isset($extra_tabs[0]) ? $extra_tabs : array($extra_tabs) as $extra_tab) diff --git a/importexport/inc/class.importexport_widget_filter.inc.php b/importexport/inc/class.importexport_widget_filter.inc.php index 863d582e7e..ac5bfe7259 100644 --- a/importexport/inc/class.importexport_widget_filter.inc.php +++ b/importexport/inc/class.importexport_widget_filter.inc.php @@ -41,7 +41,7 @@ class importexport_widget_filter extends Etemplate\Widget\Transformer public function beforeSendToClient($cname, Array $expand = Array()) { $form_name = self::form_name($cname, $this->id); - if($this->getElementAttribute($form_name, 'customfields')) + if(self::getElementAttribute($form_name, 'customfields')) { // Already done? Still need to process, or sel_options may be missing unset(self::$request->modifications[$form_name]);