class FieldsManager (View source)

Class to manage fields

Properties

DoliDB $db
string $error
string[] $errors
array<string, string> $validateFieldsErrors
string $fieldsPath
static CommonField> $fieldClasses
static FieldInfos>}>> $fieldInfos
array<string, bool|int<0, 1>>|null $expand_display

Methods

__construct(DoliDB $db, Form|null $form = null)

Constructor

getFieldClass(string $type)

Get field handler for the provided type

CommonField>
getAllFields()

Get all fields handler available

void
clearErrors()

clear errors

string
errorsToString(string $separator = ', ')

Method to output saved errors

void
clearFieldError(string $fieldKey)

clear validation message result for a field

void
setFieldError(string $fieldKey, string $msg = '')

set validation error message a field

string
getFieldError(string $fieldKey)

get field error message

string
getFieldErrorIcon(string $fieldValidationErrorMsg)

get field error icon

FieldInfos>}
getAllFieldsInfos(CommonObject $object, ExtraFields $extrafields = null, string $mode = 'view', int $nbColumn = 2, array<int, string> $breakKeys = array(), array<string, mixed> $params = array())

Get list of fields infos for the provided mode into X columns

FieldInfos>
getAllObjectFieldsInfos(CommonObject $object, string $mode = 'view', array<string, mixed> $params = array())

Get list of object fields infos

FieldInfos>
getAllExtraFieldsInfos(CommonObject $object, ExtraFields $extrafields = null, string $mode = 'view', array<string, mixed> $params = array())

Get list of extra fields infos

FieldInfos|null
getFieldsInfos(string $key, CommonObject $object, ExtraFields $extrafields = null, string $mode = 'view', array<string, mixed> $params = array())

Get list of fields infos for the provided mode into X columns

FieldInfos|null
getFieldInfosFromObjectField(CommonObject $object, string $key, string $mode = 'view', array<string, mixed> $params = array())

Get field infos from object field infos

FieldInfos|null
getFieldInfosFromExtraField(CommonObject $object, ExtraFields $extrafields, string $key, string $mode = 'view', array<string, mixed> $params = array())

Get field infos from extra field infos

void
setCommonFieldInfos(FieldInfos $fieldInfos, CommonObject $object, ExtraFields $extrafields, string $key, string $mode = 'view', string $enabled = '1', string $visibility = '', string $perms = null, array<string, mixed> $params = array())

Set common field infos

int
setFieldValuesFromPost(CommonObject $object, ExtraFields $extrafields, string $keyPrefix = '', string $keySuffix = '', string $mode = 'view', array<string, mixed> $params = array())

Set all values of the object (with extra field) from POST

int
setObjectFieldValuesFromPost(CommonObject $object, string $keyPrefix = '', string $keySuffix = '', string $mode = 'view', array<string, mixed> $params = array())

Set all object values of the object from POST

int
setExtraFieldValuesFromPost(CommonObject $object, ExtraFields $extrafields, string $keyPrefix = '', string $keySuffix = '', string $mode = 'view', array<string, mixed> $params = array())

Set all extra field values of the object from POST

bool
verifyPostFieldValue(FieldInfos $fieldInfos, string $key, string $keyPrefix = '', string $keySuffix = '')

Verify if the field value is valid

bool
verifyFieldValue(FieldInfos $fieldInfos, string $key, mixed $value)

Verify if the field value is valid

mixed
getPostFieldValue(FieldInfos $fieldInfos, string $key, mixed $defaultValue = null, string $keyPrefix = '', string $keySuffix = '')

Get field value from GET/POST

mixed
getPostSearchFieldValue(FieldInfos $fieldInfos, string $key, mixed $defaultValue = null, string $keyPrefix = '', string $keySuffix = '')

Get search field value from GET/POST

string
printInputSearchField(FieldInfos $fieldInfos, string $key, mixed $value, string $keyPrefix = '', string $keySuffix = '', string $moreCss = '', string $moreAttrib = '', int<0, 1> $noNewButton = 0)

Return HTML string to put an input search field into a page

string
printInputField(FieldInfos $fieldInfos, string $key, mixed $value, string $keyPrefix = '', string $keySuffix = '', string $moreCss = '', string $moreAttrib = '', int<0, 1> $noNewButton = 0)

Return HTML string to put an input field into a page

string
printOutputField(FieldInfos $fieldInfos, string $key, mixed $value, string $keyPrefix = '', string $keySuffix = '', string $moreCss = '', string $moreAttrib = '')

Return HTML string to show a field into a page

string
printSeparator(string $key, object $object, int $colspan = 2, string $display_type = 'card', string $mode = 'view')

Return HTML string to print separator field

Details

__construct(DoliDB $db, Form|null $form = null)

Constructor

Parameters

DoliDB $db

Database handler

Form|null $form

Specific form handler

CommonField|null getFieldClass(string $type)

Get field handler for the provided type

Parameters

string $type

Field type

Return Value

CommonField|null

CommonField> getAllFields()

Get all fields handler available

Return Value

CommonField>

void clearErrors()

clear errors

Return Value

void

string errorsToString(string $separator = ', ')

Method to output saved errors

Parameters

string $separator

Separator between each error

Return Value

string

String with errors

void clearFieldError(string $fieldKey)

clear validation message result for a field

Parameters

string $fieldKey

Key of attribute to clear

Return Value

void

void setFieldError(string $fieldKey, string $msg = '')

set validation error message a field

Parameters

string $fieldKey

Key of attribute

string $msg

the field error message

Return Value

void

string getFieldError(string $fieldKey)

get field error message

Parameters

string $fieldKey

Key of attribute

Return Value

string

Error message of validation ('' if no error)

string getFieldErrorIcon(string $fieldValidationErrorMsg)

get field error icon

Parameters

string $fieldValidationErrorMsg

message to add in tooltip

Return Value

string

html output

FieldInfos>} getAllFieldsInfos(CommonObject $object, ExtraFields $extrafields = null, string $mode = 'view', int $nbColumn = 2, array<int, string> $breakKeys = array(), array<string, mixed> $params = array())

Get list of fields infos for the provided mode into X columns

Parameters

CommonObject $object

Object handler

ExtraFields $extrafields

ExtraFields handler

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

int $nbColumn

Split fields infos into X columns

array<int, string> $breakKeys

Key used for break on each column (ex: array(1 => 'total_ht', ...))

array<string, mixed> $params

Other params

Return Value

FieldInfos>}

List of fields info by column and hidden

FieldInfos> getAllObjectFieldsInfos(CommonObject $object, string $mode = 'view', array<string, mixed> $params = array())

Get list of object fields infos

Parameters

CommonObject $object

Object handler

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

FieldInfos>

List of fields infos

FieldInfos> getAllExtraFieldsInfos(CommonObject $object, ExtraFields $extrafields = null, string $mode = 'view', array<string, mixed> $params = array())

Get list of extra fields infos

Parameters

CommonObject $object

Object handler

ExtraFields $extrafields

ExtraFields handler

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

FieldInfos>

List of fields infos

FieldInfos|null getFieldsInfos(string $key, CommonObject $object, ExtraFields $extrafields = null, string $mode = 'view', array<string, mixed> $params = array())

Get list of fields infos for the provided mode into X columns

Parameters

string $key

Field key (begin by object for object or options for extrafields)

CommonObject $object

Object handler

ExtraFields $extrafields

ExtraFields handler

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

FieldInfos|null

Get field info or null if not found

FieldInfos|null getFieldInfosFromObjectField(CommonObject $object, string $key, string $mode = 'view', array<string, mixed> $params = array())

Get field infos from object field infos

Parameters

CommonObject $object

Object handler

string $key

Field key

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

FieldInfos|null

Properties of the field or null if field not found

FieldInfos|null getFieldInfosFromExtraField(CommonObject $object, ExtraFields $extrafields, string $key, string $mode = 'view', array<string, mixed> $params = array())

Get field infos from extra field infos

Parameters

CommonObject $object

Object handler

ExtraFields $extrafields

Extrafields handler

string $key

Field key

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

FieldInfos|null

Properties of the field or null if not found

void setCommonFieldInfos(FieldInfos $fieldInfos, CommonObject $object, ExtraFields $extrafields, string $key, string $mode = 'view', string $enabled = '1', string $visibility = '', string $perms = null, array<string, mixed> $params = array())

Set common field infos

Parameters

FieldInfos $fieldInfos

Field infos to set with common infos

CommonObject $object

Object handler

ExtraFields $extrafields

Extrafields handler

string $key

Field key

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

string $enabled

Condition when the field must be managed (Example: 1 or 'getDolGlobalInt("MY_SETUP_PARAM")' or 'isModEnabled("multicurrency")' ...)

string $visibility

Condition when the field must be visible (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form (not create). 5=Visible on list and view form (not create/not update). 6=visible on list and update/view form (not create). Using a negative value means field is not shown by default on list but can be selected for viewing)

string $perms

Condition when the field must be editable

array<string, mixed> $params

Other params

Return Value

void

int setFieldValuesFromPost(CommonObject $object, ExtraFields $extrafields, string $keyPrefix = '', string $keySuffix = '', string $mode = 'view', array<string, mixed> $params = array())

Set all values of the object (with extra field) from POST

Parameters

CommonObject $object

Object handler

ExtraFields $extrafields

Extrafields handler

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

int

Result <0 if KO, >0 if OK

int setObjectFieldValuesFromPost(CommonObject $object, string $keyPrefix = '', string $keySuffix = '', string $mode = 'view', array<string, mixed> $params = array())

Set all object values of the object from POST

Parameters

CommonObject $object

Object handler

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

int

Result <0 if KO, >0 if OK

int setExtraFieldValuesFromPost(CommonObject $object, ExtraFields $extrafields, string $keyPrefix = '', string $keySuffix = '', string $mode = 'view', array<string, mixed> $params = array())

Set all extra field values of the object from POST

Parameters

CommonObject $object

Object handler

ExtraFields $extrafields

Extrafields handler

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

string $mode

Get the fields infos for the provided mode ('create', 'edit', 'view', 'list')

array<string, mixed> $params

Other params

Return Value

int

Result <0 if KO, >0 if OK

bool verifyPostFieldValue(FieldInfos $fieldInfos, string $key, string $keyPrefix = '', string $keySuffix = '')

Verify if the field value is valid

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of attribute

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

Return Value

bool

bool verifyFieldValue(FieldInfos $fieldInfos, string $key, mixed $value)

Verify if the field value is valid

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of field

mixed $value

Value to check (for date type it must be in timestamp format, for amount or price it must be a php numeric value, for array type must be array)

Return Value

bool

mixed getPostFieldValue(FieldInfos $fieldInfos, string $key, mixed $defaultValue = null, string $keyPrefix = '', string $keySuffix = '')

Get field value from GET/POST

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of field

mixed $defaultValue

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 array type must be array)

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

Return Value

mixed

mixed getPostSearchFieldValue(FieldInfos $fieldInfos, string $key, mixed $defaultValue = null, string $keyPrefix = '', string $keySuffix = '')

Get search field value from GET/POST

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of field

mixed $defaultValue

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 array type must be array)

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

Return Value

mixed

string printInputSearchField(FieldInfos $fieldInfos, string $key, mixed $value, string $keyPrefix = '', string $keySuffix = '', string $moreCss = '', string $moreAttrib = '', int<0, 1> $noNewButton = 0)

Return HTML string to put an input search field into a page

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of attribute

mixed $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 array type must be array)

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

string $moreCss

Value for css to define style/length of field.

string $moreAttrib

To add more attributes on html input tag

int<0, 1> $noNewButton

Force to not show the new button on field that are links to object

Return Value

string

string printInputField(FieldInfos $fieldInfos, string $key, mixed $value, string $keyPrefix = '', string $keySuffix = '', string $moreCss = '', string $moreAttrib = '', int<0, 1> $noNewButton = 0)

Return HTML string to put an input field into a page

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of attribute

mixed $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 array type must be array)

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

string $moreCss

Value for css to define style/length of field.

string $moreAttrib

To add more attributes on html input tag

int<0, 1> $noNewButton

Force to not show the new button on field that are links to object

Return Value

string

string printOutputField(FieldInfos $fieldInfos, string $key, mixed $value, string $keyPrefix = '', string $keySuffix = '', string $moreCss = '', string $moreAttrib = '')

Return HTML string to show a field into a page

Parameters

FieldInfos $fieldInfos

Properties of the field

string $key

Key of attribute

mixed $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 array type must be array)

string $keyPrefix

Prefix string to add into name and id of field (can be used to avoid duplicate names)

string $keySuffix

Suffix string to add into name and id of field (can be used to avoid duplicate names)

string $moreCss

Value for css to define style/length of field.

string $moreAttrib

To add more attributes on html input tag

Return Value

string

string printSeparator(string $key, object $object, int $colspan = 2, string $display_type = 'card', string $mode = 'view')

Return HTML string to print separator field

Parameters

string $key

Key of attribute

object $object Object
int $colspan

Value of colspan to use (it must include the first column with title)

string $display_type

"card" for form display, "line" for document line display

string $mode

Show output ('view') or input ('create' or 'edit') for field

Return Value

string

HTML code with line for separator