class FormSetup (View source)

This class help you create setup render.

See Example in modulebuilder/template/admin/setup.php to know how to use this utility class.

Properties

DoliDB $db
int $entity
FormSetupItem[] $items
int $setupNotEmpty
Translate $langs
Form $form
protected int $maxItemRank
string $htmlBeforeOutputForm

Html string display before output form

string $htmlAfterOutputForm

Html string to display after output form

string $htmlOutputMoreButton

Html string to display on buttons zone

array<string, string> $formAttributes
array<string, string> $formHiddenInputs

an list of hidden inputs used only in edit mode

string[] $errors

Methods

__construct(DoliDB $db, Translate $outputLangs = null)

Constructor

static string
generateAttributesStringFromArray(array<string, mixed|mixed[]|object> $attributes)

Generate an attributes string form an input array

string
generateOutput(bool $editMode = false, bool $hideTitle = false, string $title = '', string $cssfirstcolumn = '')

Generate the form (in read or edit mode depending on $editMode)

string
generateTableOutput(bool $editMode = false, bool $hideTitle = false, string $title = '', string $cssfirstcolumn = '')

generateTableOutput

int|null
saveConfFromPost(bool $noMessageInUpdate = false)

saveConfFromPost

string
generateLineOutput(FormSetupItem $item, bool $editMode = false)

generateLineOutput

bool
addItemsFromParamsArray(array<array<string, null|int|float|string>> $params)

Method used to test module builder conversion to this form usage

bool
addItemFromParams(string $confKey, array<string, null|int|float|string> $params)

From old Method was used to test module builder conversion to this form usage.

array<string, array{type: string, enabled: int<0, 1>}>
exportItemsAsParamsArray()

Used to export param array for /core/actions_setmoduleoptions.inc.php template Method exists only for manage setup conversion

bool
reloadConfs()

Reload for each item default conf note: this will override custom configuration

newItem(string $confKey, string $targetItemKey = '', bool $insertAfterTarget = false)

Create a new item The target is useful with hooks : that allow externals modules to add setup items on good place

bool
sortingItems()

Sort items according to rank

int
getCurentItemMaxRank(bool $cache = true)

getCurentItemMaxRank

void
setItemMaxRank(int $rank)

set new max rank if needed

int
getLineRank(string $itemKey)

get item position rank from item key

itemSort(FormSetupItem $a, FormSetupItem $b)

uasort callback function to Sort params items

Details

__construct(DoliDB $db, Translate $outputLangs = null)

Constructor

Parameters

DoliDB $db

Database handler

Translate $outputLangs

if needed can use another lang

static string generateAttributesStringFromArray(array<string, mixed|mixed[]|object> $attributes)

Generate an attributes string form an input array

Parameters

array<string, mixed|mixed[]|object> $attributes

an array of attributes keys and values,

Return Value

string

attribute string

string generateOutput(bool $editMode = false, bool $hideTitle = false, string $title = '', string $cssfirstcolumn = '')

Generate the form (in read or edit mode depending on $editMode)

Parameters

bool $editMode

True will display output on edit mod

bool $hideTitle

True to hide the first title line

string $title

Title of first line

string $cssfirstcolumn

CSS first column

Return Value

string

Html output

string generateTableOutput(bool $editMode = false, bool $hideTitle = false, string $title = '', string $cssfirstcolumn = '')

generateTableOutput

Parameters

bool $editMode

True will display output on edit modECM

bool $hideTitle

True to hide the first title line

string $title

Title of first line

string $cssfirstcolumn

CSS first column

Return Value

string

Html output

int|null saveConfFromPost(bool $noMessageInUpdate = false)

saveConfFromPost

Parameters

bool $noMessageInUpdate

display event message on errors and success

Return Value

int|null

Return -1 if KO, 1 if OK, null if no items

string generateLineOutput(FormSetupItem $item, bool $editMode = false)

generateLineOutput

Parameters

FormSetupItem $item

the setup item

bool $editMode

Display as edit mod

Return Value

string

the html output for an setup item

bool addItemsFromParamsArray(array<array<string, null|int|float|string>> $params)

Method used to test module builder conversion to this form usage

Parameters

array<array<string, null|int|float|string>> $params

an array of arrays of params from old modulBuilder params

Return Value

bool

bool addItemFromParams(string $confKey, array<string, null|int|float|string> $params)

From old Method was used to test module builder conversion to this form usage.

Parameters

string $confKey

the conf name to store

array<string, null|int|float|string> $params

an array of params from old modulBuilder params

Return Value

bool

array<string, array{type: string, enabled: int<0, 1>}> exportItemsAsParamsArray()

Used to export param array for /core/actions_setmoduleoptions.inc.php template Method exists only for manage setup conversion

Return Value

array<string, array{type: string, enabled: int<0, 1>}>

$arrayofparameters for /core/actions_setmoduleoptions.inc.php

bool reloadConfs()

Reload for each item default conf note: this will override custom configuration

Return Value

bool

FormSetupItem newItem(string $confKey, string $targetItemKey = '', bool $insertAfterTarget = false)

Create a new item The target is useful with hooks : that allow externals modules to add setup items on good place

Parameters

string $confKey

the conf key used in database

string $targetItemKey

target item used to place the new item beside

bool $insertAfterTarget

insert before or after target item ?

Return Value

FormSetupItem

the new setup item created

bool sortingItems()

Sort items according to rank

Return Value

bool

int getCurentItemMaxRank(bool $cache = true)

getCurentItemMaxRank

Parameters

bool $cache

To use cache or not

Return Value

int

void setItemMaxRank(int $rank)

set new max rank if needed

Parameters

int $rank

the item rank

Return Value

void

new max rank

int getLineRank(string $itemKey)

get item position rank from item key

Parameters

string $itemKey

the item key

Return Value

int

rank on success and -1 on error

itemSort(FormSetupItem $a, FormSetupItem $b)

uasort callback function to Sort params items

@param FormSetupItem $a formSetup item

Parameters

FormSetupItem $a
FormSetupItem $b

formSetup item @return int Return compare result