change api\Etemplate\Widget::getElementAttribute($name,$attr) to NO longer return a reference, use setElementAttribute($name,$attr) if you need a reference

This commit is contained in:
ralf 2024-10-24 21:25:20 +02:00
parent 1612ddb030
commit 2552bea6a2
8 changed files with 35 additions and 31 deletions

View File

@ -644,7 +644,7 @@ class Etemplate extends Etemplate\Widget\Template
* @return mixed reference to attribute, usually NULL * @return mixed reference to attribute, usually NULL
* @deprecated use getElementAttribute($name, $attr) * @deprecated use getElementAttribute($name, $attr)
*/ */
public function &get_cell_attribute($name,$attr) public function get_cell_attribute($name,$attr)
{ {
return self::getElementAttribute($name, $attr); return self::getElementAttribute($name, $attr);
} }

View File

@ -1075,14 +1075,15 @@ class Widget
/** /**
* Returns reference to an attribute in a named cell * 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 no longer return a reference to the attribute!
* We do not return a reference to the actual cell, as it get's contructed on client-side! *
* If you need a reference, use: $attr =& setElementAttribute($name, $attr)
* *
* @param string $name cell-name * @param string $name cell-name
* @param string $attr attribute-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')"); //error_log(__METHOD__."('$name', '$attr')");
return self::$request->modifications[$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 * @param mixed $val if not NULL sets attribute else returns it
* @return reference to attribute * @return reference to attribute
*/ */
public static function &setElementAttribute($name,$attr,$val) public static function &setElementAttribute($name,$attr,$val=null)
{ {
if (!isset(self::$request)) 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()); //error_log(__METHOD__."('$name', '$attr', ...) request=".get_class(self::$request).", response=".get_class(self::$response).function_backtrace());
$ref =& self::$request->modifications[$name][$attr]; $ref =& self::$request->modifications[$name][$attr];
if(self::$request && self::$response) if(self::$request && self::$response && isset($val))
{ {
// In an AJAX response - automatically add // In an AJAX response - automatically add
self::$response->generic('assign',array( self::$response->generic('assign',array(
@ -1119,8 +1120,10 @@ class Widget
self::$request->unset_to_process(''); self::$request->unset_to_process('');
//error_log(__METHOD__."('$name', '$attr', ...) ".function_backtrace()); //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).')'); //error_log(__METHOD__."('$name', '$attr', ".array2string($val).')');
return $ref; return $ref;
} }
@ -1130,7 +1133,7 @@ class Widget
* *
* @param string $name cell-name * @param string $name cell-name
* @param boolean $disabled =true disable or enable a cell, default true=disable * @param boolean $disabled =true disable or enable a cell, default true=disable
* @return reference to attribute * @return attribute
*/ */
public function disableElement($name,$disabled=True) public function disableElement($name,$disabled=True)
{ {

View File

@ -104,10 +104,10 @@ class Customfields extends Transformer
} }
else else
{ {
$app =& $this->getElementAttribute(self::GLOBAL_VALS, 'app'); $app =& self::setElementAttribute(self::GLOBAL_VALS, 'app');
if($this->getElementAttribute($form_name, 'app')) if(self::getElementAttribute($form_name, 'app'))
{ {
$app =& $this->getElementAttribute($form_name, 'app'); $app =& self::setElementAttribute($form_name, 'app');
} }
else 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) elseif($app)
{ {
// Checking creates it even if it wasn't there // Checking creates it even if it wasn't there
unset(self::$request->modifications[$form_name]['customfields']); unset(self::$request->modifications[$form_name]['customfields']);
$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields'); $customfields =& self::setElementAttribute(self::GLOBAL_VALS, 'customfields');
} }
if(!$app && !$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 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); 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)); //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 else
{ {
$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields'); $customfields =& self::setElementAttribute(self::GLOBAL_VALS, 'customfields');
} }
if(is_array($value_in)) if(is_array($value_in))
{ {

View File

@ -149,9 +149,10 @@ class Select extends Etemplate\Widget
{ {
$widget_type = substr($widget_type, 4); $widget_type = substr($widget_type, 4);
} }
$multiple = $this->attrs['multiple'] || $this->getElementAttribute($form_name, 'multiple') || $this->getElementAttribute($form_name, 'rows') > 1; $multiple = $this->attrs['multiple'] || self::getElementAttribute($form_name, 'multiple') ||
$allowFreeEntries = $this->attrs['allowFreeEntries'] || $this->getElementAttribute($form_name, 'allowFreeEntries') || self::getElementAttribute($form_name, 'rows') > 1;
$this->attrs['searchUrl'] || $this->getElementAttribute($form_name, 'searchUrl'); $allowFreeEntries = $this->attrs['allowFreeEntries'] || self::getElementAttribute($form_name, 'allowFreeEntries') ||
$this->attrs['searchUrl'] || self::getElementAttribute($form_name, 'searchUrl');
$ok = true; $ok = true;
if (!$this->is_readonly($cname, $form_name)) if (!$this->is_readonly($cname, $form_name))

View File

@ -54,7 +54,7 @@ class Tabbox extends Etemplate\Widget
$form_name = self::form_name($params[0], $this->id, $params[1]); $form_name = self::form_name($params[0], $this->id, $params[1]);
// Make sure additional tabs are processed for any method // 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']; $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 // 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) $extra_tabs = array_filter($extra_tabs, static function($tab)
{ {

View File

@ -110,7 +110,7 @@ class calendar_favorite_portlet extends home_favorite_portlet
$content = array(); $content = array();
$etemplate->read('calendar.planner'); $etemplate->read('calendar.planner');
$etemplate->set_dom_id($id); $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 // Don't notify the calendar app of date changes
$etemplate->setElementAttribute('planner','onchange',false); $etemplate->setElementAttribute('planner','onchange',false);
$ui->planner_view = $this->favorite['state']['planner_view']; $ui->planner_view = $this->favorite['state']['planner_view'];
@ -120,7 +120,7 @@ class calendar_favorite_portlet extends home_favorite_portlet
case 'weekN': case 'weekN':
$etemplate->read('calendar.view'); $etemplate->read('calendar.view');
$etemplate->set_dom_id($id); $etemplate->set_dom_id($id);
$this->actions =& $etemplate->getElementAttribute('view', 'actions'); $this->actions =& $etemplate->setElementAttribute('view', 'actions');
$ui->month($this->favorite['state']['view'] == 'month' ? $ui->month($this->favorite['state']['view'] == 'month' ?
0 : 0 :
@ -131,7 +131,7 @@ class calendar_favorite_portlet extends home_favorite_portlet
case 'week': case 'week':
$etemplate->read('calendar.view'); $etemplate->read('calendar.view');
$etemplate->set_dom_id($id); $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 // Don't notify the calendar app of date changes
$etemplate->setElementAttribute('view[0]','onchange',false); $etemplate->setElementAttribute('view[0]','onchange',false);
$ui->week(array(), $etemplate); $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'] : ( $days = $this->favorite['state']['days'] ? $this->favorite['state']['days'] : (
$this->favorite['state']['view'] == 'day' ? 1 : 4 $this->favorite['state']['view'] == 'day' ? 1 : 4
); );
$this->actions =& $etemplate->getElementAttribute('view', 'actions'); $this->actions =& $etemplate->setElementAttribute('view', 'actions');
$ui->week($days, $etemplate); $ui->week($days, $etemplate);
return; return;
} }
@ -262,4 +262,4 @@ class calendar_favorite_portlet extends home_favorite_portlet
{ {
return 'et2-portlet-calendar'; return 'et2-portlet-calendar';
} }
} }

View File

@ -1623,7 +1623,7 @@ class filemanager_ui
// add to existing tabs in template // add to existing tabs in template
$tpl->setElementAttribute('tabs', 'add_tabs', true); $tpl->setElementAttribute('tabs', 'add_tabs', true);
$tabs =& $tpl->getElementAttribute('tabs', 'extraTabs'); $tabs =& $tpl->setElementAttribute('tabs', 'extraTabs');
if (true) $tabs = array(); if (true) $tabs = array();
foreach(isset($extra_tabs[0]) ? $extra_tabs : array($extra_tabs) as $extra_tab) foreach(isset($extra_tabs[0]) ? $extra_tabs : array($extra_tabs) as $extra_tab)

View File

@ -41,7 +41,7 @@ class importexport_widget_filter extends Etemplate\Widget\Transformer
public function beforeSendToClient($cname, Array $expand = Array()) public function beforeSendToClient($cname, Array $expand = Array())
{ {
$form_name = self::form_name($cname, $this->id); $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 // Already done? Still need to process, or sel_options may be missing
unset(self::$request->modifications[$form_name]); unset(self::$request->modifications[$form_name]);