From ea9f0097a284277122ca71715e02187a9e6f03b5 Mon Sep 17 00:00:00 2001 From: Matt Sidnell <54064522+pstructures@users.noreply.github.com> Date: Mon, 20 Apr 2020 22:42:13 +0100 Subject: [PATCH 1/4] Add default values for Create Added default extrafield values for html and text fields to prepopulate data on record create only. --- htdocs/core/class/commonobject.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4b94f87c65f..f881a89c204 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7117,6 +7117,14 @@ abstract class CommonObject { $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; } + + // HTML and text add default value + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text'))) + { + if($action=='create') $value = $extrafields->attributes[$this->table_element]['default'][$key]; + else $value = $this->array_options['options_'.$key]; + } + $labeltoshow = $langs->trans($label); $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]); From 59b574742b1f18ab6159e96eff8a06cd4d8a8d06 Mon Sep 17 00:00:00 2001 From: Matt Sidnell <54064522+pstructures@users.noreply.github.com> Date: Mon, 20 Apr 2020 22:52:36 +0100 Subject: [PATCH 2/4] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f881a89c204..83de743931c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7124,7 +7124,14 @@ abstract class CommonObject if($action=='create') $value = $extrafields->attributes[$this->table_element]['default'][$key]; else $value = $this->array_options['options_'.$key]; } - + + // select fields use default value + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('select'))) + { + if($action=='create') $value = $extrafields->attributes[$this->table_element]['default'][$key]; + else $value = $this->array_options['options_'.$key]; + } + $labeltoshow = $langs->trans($label); $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]); From 3f42bfb40f614d1e69454226502947ee6bf3045d Mon Sep 17 00:00:00 2001 From: mattsidnell Date: Mon, 20 Apr 2020 23:42:12 +0100 Subject: [PATCH 3/4] change --- htdocs/core/class/commonobject.class.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 83de743931c..02445a218c1 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7117,16 +7117,9 @@ abstract class CommonObject { $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; } - - // HTML and text add default value - if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text'))) - { - if($action=='create') $value = $extrafields->attributes[$this->table_element]['default'][$key]; - else $value = $this->array_options['options_'.$key]; - } - - // select fields use default value - if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('select'))) + + // HTML, select, integer and text add default value + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'select', 'int'))) { if($action=='create') $value = $extrafields->attributes[$this->table_element]['default'][$key]; else $value = $this->array_options['options_'.$key]; From 9040c9680db3b4216f1a29b46b153f6812d2b7b2 Mon Sep 17 00:00:00 2001 From: mattsidnell Date: Mon, 20 Apr 2020 23:44:23 +0100 Subject: [PATCH 4/4] Removed whitespace --- htdocs/core/class/commonobject.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 02445a218c1..b091caa548a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7117,7 +7117,6 @@ abstract class CommonObject { $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; } - // HTML, select, integer and text add default value if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'select', 'int'))) {