Fix #30766 Extra field Can Always Be Edited (#31876)

* fix alwayseditable

* Update extrafields.class.php

* Update extrafields.class.php

* Update extrafields.class.php

* enhance fix alwayseditable

* fix phan
This commit is contained in:
Mohamed DAOUD
2024-11-20 21:33:32 +01:00
committed by GitHub
parent de8d705eeb
commit f71bb45bd7
2 changed files with 20 additions and 11 deletions

View File

@@ -9393,14 +9393,14 @@ abstract class CommonObject
$out .= getPictoForType($extrafields->attributes[$this->table_element]['type'][$key], ($extrafields->attributes[$this->table_element]['type'][$key] == 'text' ? 'tdtop' : ''));
}
//$out .= '<!-- type = '.$extrafields->attributes[$this->table_element]['type'][$key].' -->';
$out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id, $this->table_element);
$out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this, $this->table_element);
break;
case "edit":
$listoftypestoshowpicto = explode(',', getDolGlobalString('MAIN_TYPES_TO_SHOW_PICTO', 'email,phone,ip,password'));
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], $listoftypestoshowpicto)) {
$out .= getPictoForType($extrafields->attributes[$this->table_element]['type'][$key], ($extrafields->attributes[$this->table_element]['type'][$key] == 'text' ? 'tdtop' : ''));
}
$out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', '', $this->id, $this->table_element);
$out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', '', $this, $this->table_element);
break;
}

View File

@@ -1076,18 +1076,18 @@ class ExtraFields
* Return HTML string to put an input field into a page
* Code very similar with showInputField of common object
*
* @param string $key Key of attribute
* @param string $key Key of attribute
* @param string|array{start:int,end:int} $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value); for dates in filter mode, a range array('start'=><timestamp>, 'end'=><timestamp>) should be provided
* @param string $moreparam To add more parameters on html input tag
* @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
* @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
* @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric)
* @param int $objectid Current object id
* @param string $extrafieldsobjectkey The key to use to store retrieved data (commonly $object->table_element)
* @param int $mode 1=Used for search filters
* @param string $moreparam To add more parameters on html input tag
* @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
* @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
* @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric)
* @param int|CommonObject $object Current object or object ID. Preferably, pass the object itself.
* @param string $extrafieldsobjectkey The key to use to store retrieved data (commonly $object->table_element)
* @param int $mode 1=Used for search filters
* @return string
*/
public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '', $mode = 0)
public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $object = 0, $extrafieldsobjectkey = '', $mode = 0)
{
global $conf, $langs, $form;
@@ -1096,6 +1096,8 @@ class ExtraFields
$form = new Form($this->db);
}
$objectid = (is_numeric($object) ? $object : $object->id);
$out = '';
if (!preg_match('/options_$/', $keyprefix)) { // Because we work on extrafields, we add 'options_' to prefix if not already added
@@ -1120,6 +1122,7 @@ class ExtraFields
$list = (string) dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1, 1, '2');
$totalizable = $this->attributes[$extrafieldsobjectkey]['totalizable'][$key];
$help = $this->attributes[$extrafieldsobjectkey]['help'][$key];
$alwayseditable = $this->attributes[$extrafieldsobjectkey]['alwayseditable'][$key];
$hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
//var_dump('key='.$key.' '.$value.' '.$moreparam.' '.$keysuffix.' '.$keyprefix.' '.$objectid.' '.$extrafieldsobjectkey.' '.$mode);
@@ -1935,6 +1938,12 @@ class ExtraFields
if (!empty($hidden)) {
$out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>';
}
// If alwayseditable is false, and object is not in draft, then showOutputField
// @phan-suppress-next-line PhanUndeclaredConstantOfClass
if ($alwayseditable == 0 && !is_numeric($object) && isset($object->status) && $object->status != $object::STATUS_DRAFT) {
$out = $this->showOutputField($key, $value, $moreparam, $extrafieldsobjectkey, null, $object);
}
/* Add comments
if ($type == 'date') $out.=' (YYYY-MM-DD)';
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';