439
edits
| Line 356: | Line 356: | ||
findLabel() findLabelPDF() | findLabel() findLabelPDF() | ||
= Facade API = | |||
The Facade API was made to ease the usage of the CustomFields class with the Dolibarr system. It provides a neat way to do many operations with single commands, and will automatically manage the loading of the CustomFields class, and its usage with many optimizations. | |||
== customfields_fill_object() == | |||
You can load the Facade API and then use the '''customfields_fill_object()''' to automatically fetch the fields structures and the records, and also automatically link to remote fields when a constrained field is found. This is an all-in-one solution to easily fetch CustomFields datas, and is also optimized to fully use caching and other special properties of the CustomFields class. | You can load the Facade API and then use the '''customfields_fill_object()''' to automatically fetch the fields structures and the records, and also automatically link to remote fields when a constrained field is found. This is an all-in-one solution to easily fetch CustomFields datas, and is also optimized to fully use caching and other special properties of the CustomFields class. | ||
=== customfields_fill_object_lines() | Concretely, you just have to include the Facade API, then pass the customfields_fill_object() with a Dolibarr $object, and the Facade API will return a CustomFields object with appended the custom fields records and also the custom fields' SQL structures. | ||
<source lang="php"> | |||
// Init and main vars for CustomFields | |||
dol_include_once('/customfields/lib/customfields_aux.lib.php'); | |||
// Filling the $object with customfields (you can then access customfields by doing $object->customfields->cf_yourfield) | |||
$customfields = customfields_fill_object($object); | |||
</source> | |||
* $object will then include the custom fields records associated with this object (eg: $object->customfields->cf_yourfield). | |||
* $customfields will be a CustomFields object containing the fields structures (eg: $customfields->fields->yourfield). | |||
You can also call any CustomFields function if you need to using the $customfields object, eg: $customfields->simpleprintField($object->customfields->cf_yourfield); | |||
Note: $object can also be a dummy object containing only two properties that are required: $object->id and $object->table_element. | |||
For more informations on pratical usages of this function, please [[Module_CustomFields#Implementing_in_php_code_.28dolibarr_core_modules_or_your_own_module.29|read the user documentation on how to implement CustomFields in php code]]. | |||
== customfields_fill_object_lines() == | |||
Similar to customfields_fill_object() for normal custom fields, there is also a '''customfields_fill_object_lines()''' to fetch custom fields associated with lines of products/services. This function is also optimized and it is strongly advised to use it and to not try to fetch manually this kind of custom fields (ie: associated with lines of products/services rather than objects), because there are a lot of optimizations going on behind the scene and that are very hard to do manually. | Similar to customfields_fill_object() for normal custom fields, there is also a '''customfields_fill_object_lines()''' to fetch custom fields associated with lines of products/services. This function is also optimized and it is strongly advised to use it and to not try to fetch manually this kind of custom fields (ie: associated with lines of products/services rather than objects), because there are a lot of optimizations going on behind the scene and that are very hard to do manually. | ||
For more informations on pratical usages of this function, please [[Module_CustomFields#Implementing_in_php_code_.28dolibarr_core_modules_or_your_own_module.29|read the user documentation on how to implement CustomFields in php code]]. | |||
= Architecture = | = Architecture = | ||
edits