2
0
forked from Wavyzz/dolibarr

Fix better comaptibilty for extrafield email/mail

This commit is contained in:
ldestailleur
2025-08-05 00:45:00 +02:00
parent eab3227ea0
commit 86f5db7aa9
8 changed files with 48 additions and 18 deletions

View File

@@ -9173,7 +9173,7 @@ abstract class CommonObject
} else {
return true;
}
} elseif ($type == 'mail') {
} elseif ($type == 'mail' || $type == 'email') {
if (!$validate->isEmail($fieldValue)) {
$this->setFieldError($fieldKey, $validate->error);
return false;

View File

@@ -49,7 +49,7 @@ class DefaultValues extends CommonObject
public $picto = '';
/**
* 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
* 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'email', 'phone', 'url', 'password')
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
* 'label' the translation key.
* 'picto' is code of a picto to show before value in forms

View File

@@ -62,7 +62,7 @@ class EmailSenderProfile extends CommonObject
/**
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'email', 'phone', 'url', 'password')
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
* 'label' the translation key.
* 'enabled' is a condition when the field must be managed.

View File

@@ -88,7 +88,7 @@ class ExtraFields
'price' => 'ExtrafieldPrice',
'pricecy' => 'ExtrafieldPriceWithCurrency',
'phone' => 'ExtrafieldPhone',
'mail' => 'ExtrafieldMail',
'email' => 'ExtrafieldMail',
'url' => 'ExtrafieldUrl',
'ip' => 'ExtrafieldIP',
'icon' => 'Icon',
@@ -142,7 +142,7 @@ class ExtraFields
*
* @param string $attrname Code of attribute
* @param string $label label of attribute
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', 'separate',...)
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'email', 'password', 'url', 'select', 'checkbox', 'separate',...)
* @param int $pos Position of attribute
* @param string $size Size/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma.
* @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...)
@@ -221,7 +221,7 @@ class ExtraFields
*
* @param string $attrname Code of attribute
* @param string $label label of attribute
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', 'separate',...)
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'email', 'password', 'url', 'select', 'checkbox', 'separate',...)
* @param int $pos Position of attribute
* @param string $size Size/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma.
* @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...)
@@ -293,7 +293,7 @@ class ExtraFields
* This is a private method. For public method, use addExtraField.
*
* @param string $attrname code of attribute
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...)
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'email', 'password', 'url', 'select', 'checkbox', ...)
* @param string $length Size/length of attribute ('5', '24,8', ...)
* @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...)
* @param int<0,1> $unique Is field unique or not
@@ -668,7 +668,7 @@ class ExtraFields
*
* @param string $attrname Name of attribute
* @param string $label Label of attribute
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...)
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'phone', 'email', 'password', 'url', 'select', 'checkbox', ...)
* @param string $length Size/length of attribute ('5', '24,8', ...)
* @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...)
* @param int<0,1> $unique Is field unique or not
@@ -723,7 +723,7 @@ class ExtraFields
} elseif ($type == 'phone') {
$typedb = 'varchar';
$lengthdb = '20';
} elseif ($type == 'mail' || $type == 'ip' || $type == 'icon') {
} elseif ($type == 'mail' || $type == 'email' || $type == 'ip' || $type == 'icon') {
$typedb = 'varchar';
$lengthdb = '128';
} elseif ($type == 'url') {
@@ -1259,7 +1259,7 @@ class ExtraFields
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>';
} elseif (preg_match('/varchar/', $type)) {
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>';
} elseif (in_array($type, array('mail', 'ip', 'phone', 'url'))) {
} elseif (in_array($type, array('email', 'mail', 'ip', 'phone', 'url'))) {
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>';
} elseif ($type == 'icon') {
/* External lib inclusion are not allowed in backoffice. Also lib is included several time if there is several icon file.
@@ -2117,7 +2117,7 @@ class ExtraFields
} else {
$value = yn($value ? 1 : 0);
}
} elseif ($type == 'mail') {
} elseif ($type == 'mail' || $type == 'email') {
$value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
} elseif ($type == 'ip') {
$value = dol_print_ip($value, 0);

View File

@@ -71,7 +71,7 @@ class TimeSpent extends CommonObject
* 'double(24,8)', 'real', 'price',
* 'date', 'datetime', 'timestamp', 'duration',
* 'boolean', 'checkbox', 'radio', 'array',
* 'mail', 'phone', 'url', 'password', 'ip'
* 'email', 'phone', 'url', 'password', 'ip'
* Note: Filter must be a Dolibarr filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)"
* 'label' the translation key.
* 'picto' is code of a picto to show before value in forms

View File

@@ -55,7 +55,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
$error = 0;
// Check parameters
// Check parameters into $addfieldentry (this provided array is filled by modulebuilder/index.php)
if (is_array($addfieldentry) && count($addfieldentry) > 0) {
if (empty($addfieldentry['name'])) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors');
@@ -66,11 +66,12 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
return -2;
}
if (!preg_match('/^(integer|price|sellist|varchar|double|text|html|duration|stars)/', $addfieldentry['type'])
&& !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|mail|url|ip|password)$/', $addfieldentry['type'])) {
&& !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|email|url|ip|password)$/', $addfieldentry['type'])) { // Use email for email, mail is kept for compatibility
setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors');
return -2;
}
// Check for type stars(NumberOfStars), NumberOfStars must be an integer between 1 and 10
$matches = array();
if (preg_match('/^stars\((.+)\)$/', $addfieldentry['type'], $matches)) {
if (!ctype_digit($matches[1]) || $matches[1] < 1 || $matches[1] > 10) {
setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors');
@@ -350,7 +351,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
$type = 'integer';
} elseif ($type == 'chkbxlst') {
$type = 'varchar(128)';
} elseif ($type == 'mail') {
} elseif ($type == 'mail' || $type == 'email') { // Prefer to use 'email'
$type = 'varchar(128)';
} elseif (strpos($type, 'stars(') === 0) {
$type = 'integer';
@@ -358,6 +359,8 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
$type = 'varchar(20)';
} elseif ($type == 'ip') {
$type = 'varchar(32)';
} elseif ($type == 'url') {
$type = 'varchar(255)';
}
$texttoinsert .= "\t".$key." ".$type;

View File

@@ -1130,7 +1130,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname && $user->hasRi
setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
} else {
/**
* 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'ip', 'url', 'password')
* 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'email', 'phone', 'ip', 'url', 'password')
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
* 'label' the translation key.
* 'picto' is code of a picto to show before value in forms
@@ -4636,7 +4636,34 @@ if ($module == 'initmodule') {
print '<input name="proplabel" class="maxwidth125" value="'.dol_escape_htmltag($proplabel).'">';
print '</td>';
print '<td class="tdoverflowmax150">';
print '<input name="proptype" class="maxwidth125" value="'.dol_escape_htmltag($proptype).'"></input>';
print '<input name="proptype" class="maxwidth125" value="'.dol_escape_htmltag($proptype).'" list="datalist'.$key.'"></input>';
// Use the samedatalist than for create
print '<datalist id="datalist'.$key.'">';
print '<option>varchar(128)</option>';
print '<option>email</option>';
print '<option>phone</option>';
print '<option>ip</option>';
print '<option>url</option>';
print '<option>password</option>';
print '<option>text</option>';
print '<option>html</option>';
print '<option>date</option>';
print '<option>datetime</option>';
print '<option>integer</option>';
print '<option>stars(5)</option>';
print '<option>double(28,4)</option>';
print '<option>real</option>';
print '<option>integer:ClassName:RelativePath/To/ClassFile.class.php[:1[:FILTER]]</option>';
// Combo with list of fields
/*
if (empty($formadmin)) {
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
$formadmin = new FormAdmin($db);
}
print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha'));
*/
print '</datalist>';
print '</td>';
print '<td class="tdoverflowmax200">';
print '<textarea name="proparrayofkeyval">';

View File

@@ -85,7 +85,7 @@ class MyObject extends CommonObject
* 'double(24,8)', 'real', 'price', 'stock',
* 'date', 'datetime', 'timestamp', 'duration',
* 'boolean', 'checkbox', 'radio', 'array',
* 'mail', 'phone', 'url', 'password', 'ip'
* 'email', 'phone', 'url', 'password', 'ip'
* Note: Filter must be a Dolibarr Universal Filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)"
* 'length' the length of field. Example: 255, '24,8'
* 'label' the translation key.