Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #30766 Extra field Can Always Be Edited #31876

Merged
merged 7 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9393,14 +9393,14 @@ public function showOptionals($extrafields, $mode = 'view', $params = null, $key
$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;
}

Expand Down
27 changes: 18 additions & 9 deletions htdocs/core/class/extrafields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1076,18 +1076,18 @@ public function fetch_name_optionals_label($elementtype, $forceload = false, $at
* 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;

Expand All @@ -1096,6 +1096,8 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $
$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
Expand All @@ -1120,6 +1122,7 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $
$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);
Expand Down Expand Up @@ -1935,6 +1938,12 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $
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)';
Expand Down
Loading