From 8ed5c2aa7ec515408cd708186c2f4723c89dcb83 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 14 Jul 2023 10:14:06 -0600 Subject: [PATCH] Get rid of a bunch of warnings in Entry & subclasses --- api/src/Etemplate/Widget/Contact.php | 14 +++++++------- api/src/Etemplate/Widget/Entry.php | 16 ++++++++-------- api/src/Etemplate/Widget/Transformer.php | 9 ++++++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/api/src/Etemplate/Widget/Contact.php b/api/src/Etemplate/Widget/Contact.php index 1b65a4b7cd..775a5c1718 100644 --- a/api/src/Etemplate/Widget/Contact.php +++ b/api/src/Etemplate/Widget/Contact.php @@ -78,13 +78,13 @@ class Contact extends Entry '__default__' => array( 'options' => array( 'bday' => array('type' => 'date', 'options' => 'Y-m-d'), - 'owner' => array('type' => 'select-account', 'options' => ''), - 'modifier' => array('type' => 'select-account', 'options' => ''), - 'creator' => array('type' => 'select-account', 'options' => ''), - 'modifed' => array('type' => 'date-time', 'options' => ''), - 'created' => array('type' => 'date-time', 'options' => ''), - 'cat_id' => array('type' => 'select-cat', 'options' => ''), - '__default__' => array('type' => 'label', 'options' => ''), + 'owner' => array('type' => 'select-account'), + 'modifier' => array('type' => 'select-account'), + 'creator' => array('type' => 'select-account'), + 'modifed' => array('type' => 'date-time'), + 'created' => array('type' => 'date-time'), + 'cat_id' => array('type' => 'select-cat'), + '__default__' => array('type' => 'label'), ), 'noLang' => true, ), diff --git a/api/src/Etemplate/Widget/Entry.php b/api/src/Etemplate/Widget/Entry.php index 1aa73d5217..2cbbc7b66f 100644 --- a/api/src/Etemplate/Widget/Entry.php +++ b/api/src/Etemplate/Widget/Entry.php @@ -69,7 +69,7 @@ abstract class Entry extends Transformer $form_name = self::form_name($cname, $this->id); $prefixed_id = (substr($this->id, 0, 1) == self::ID_PREFIX ? $this->id : self::ID_PREFIX . $this->id); - $data_id = $attrs['value'] ? self::form_name($cname, $attrs['value']) : self::form_name($cname, $prefixed_id); + $data_id = !empty($attrs['value']) ? self::form_name($cname, $attrs['value']) : self::form_name($cname, $prefixed_id); // No need to proceed if(!$data_id) return; @@ -151,9 +151,9 @@ abstract class Entry extends Transformer $value =& $data; if(!is_array($value)) return $value; - foreach(array($attrs['field']) + explode(':',$attrs['alternate_fields']) as $field) + foreach(array($attrs['field']) + explode(':', ($attrs['alternate_fields'] ?? '')) as $field) { - if($value[$field]) + if(!empty($value[$field])) { return $value[$field]; } @@ -175,12 +175,12 @@ abstract class Entry extends Transformer */ protected function customfield($attrs, &$data) { - list($app, $type) = explode('-',$attrs['type']); - $data_id = $attrs['value'] ?: $attrs['id']; + list($app, $type) = explode('-', $attrs['type']); + $data_id = isset($attrs['value']) ? $attrs['value'] : $attrs['id']; $id = is_array($data) ? static::get_array($data, $data_id) : $data; if(!$app || !$type || !$GLOBALS['egw_info']['apps'][$app] || !$id || // Simple CF, already there - $data[$attrs['field']] + isset($data[$attrs['field']]) ) { return; @@ -194,7 +194,7 @@ abstract class Entry extends Transformer $merge = new $classname(); $replacement_field = '$$'.$attrs['field'].'$$'; $replacements = $merge->get_app_replacements($app, $id, $replacement_field); - $data[$attrs['field']] = $replacements[$replacement_field]; + $data[$attrs['field']] = $replacements[$replacement_field] ?? ''; } catch(\Exception $e) { @@ -212,7 +212,7 @@ abstract class Entry extends Transformer protected function regex($attrs, &$data) { $value =& $this->get_data_field($attrs, $data); - if(!$attrs['regex'] || !$value) + if(!isset($attrs['regex']) || !$value) { return; } diff --git a/api/src/Etemplate/Widget/Transformer.php b/api/src/Etemplate/Widget/Transformer.php index efd637f385..82eceebbd6 100644 --- a/api/src/Etemplate/Widget/Transformer.php +++ b/api/src/Etemplate/Widget/Transformer.php @@ -219,15 +219,18 @@ abstract class Transformer extends Etemplate\Widget elseif(is_array($action)) { // case matches --> run all actions - if (isset($action[$attrs[$attr]]) || !isset($action[$attrs[$attr]]) && isset($action['__default__'])) + if(isset($attrs[$attr]) && isset($action[$attrs[$attr]]) || (!isset($attrs[$attr]) || !isset($action[$attrs[$attr]])) && isset($action['__default__'])) { - $actions = isset($action[$attrs[$attr]]) ? $action[$attrs[$attr]] : $action['__default__']; + $actions = isset($attrs[$attr]) && isset($action[$attrs[$attr]]) ? $action[$attrs[$attr]] : $action['__default__']; if(!is_array($actions)) { $attrs[$attr] = $actions; $actions = array($attr => $actions); } - if (self::DEBUG) error_log(__METHOD__."(attr='$attr', action=".array2string($action).") attrs['$attr']=='{$attrs[$attr]}' --> running actions"); + if(self::DEBUG) + { + error_log(__METHOD__ . "(attr='$attr', action=" . array2string($action) . ") attrs['$attr']=='{$attrs[$attr]}' --> running actions"); + } foreach($actions as $attr => $action) { $this->action($attr, $action, $attrs);