1
edit
(Adding description about "unique" property) |
(Document Object Link extrafield filter syntax (#37610)) Tag: 2017 source edit |
||
| Line 52: | Line 52: | ||
=Usage= | =Usage= | ||
==Object Link filters== | |||
An Object Link extrafield can filter the objects shown in its selection list. The descriptor format is: | |||
<syntaxhighlight lang="text"> | |||
ObjectName:classPath:<showempty>:(field:operator:value) | |||
</syntaxhighlight> | |||
For example, to show objects whose status is 1: | |||
<syntaxhighlight lang="text"> | |||
ObjectName:classPath:1:(status:=:1) | |||
</syntaxhighlight> | |||
The segments are: | |||
* <code>ObjectName</code>: the Dolibarr object name to link to. | |||
* <code>classPath</code>: the path to the PHP class for that object. | |||
* <code><showempty></code>: use 0 or 1 in this slot. Current code has a nuance: extrafield rendering derives whether to offer an empty choice from the field's Required and default-value settings, while the link-field parser treats a numeric third segment as its add-create-button flag. Do not rely on this slot to override the empty-choice setting. | |||
* <code>(field:operator:value)</code>: a filter in Dolibarr's Universal Filter Syntax. Keep it in parentheses, with the field name, operator, and value separated by colons. | |||
Supported operators are <code>=</code>, <code>!=</code>, <code><</code>, <code>></code>, <code><=</code>, <code>>=</code>, <code>in</code>, <code>notin</code>, <code>like</code>, <code>notlike</code>, <code>is</code>, and <code>isnot</code>. For example, <code>(status:=:1)</code> means <code>status = 1</code>. Criteria can be combined with <code>AND</code> or <code>OR</code>. | |||
===Placeholders and object context=== | |||
* <code>$ID$</code> is the ID of the current object. For an extrafield on an invoice line, it is the line ID, not the parent invoice ID or its third party. | |||
* <code>$MODE$</code> is replaced with the current display mode, such as list or view. | |||
* <code>$ENTITY$</code> is replaced with the current entity ID. | |||
* <code>$SEL$</code> can represent <code>SELECT</code> in a subquery only when the PHP global <code>$dolibarr_allow_unsecured_select_in_extrafields_filter</code> is enabled. This permits unsecured SELECT subqueries and is disabled unless explicitly enabled. Enabling it is an administrator security decision; a subquery should not be presented as the default workaround. | |||
The issue's example, <code>Contact:contact/class/contact.class.php:*:fk_soc=:__THIRDPARTY_ID__</code>, is malformed: the filter needs parentheses and the <code>field:operator:value</code> format. A syntactically corrected form using the supported current-object placeholder is: | |||
<syntaxhighlight lang="text"> | |||
Contact:contact/class/contact.class.php:1:(fk_soc:=:$ID$) | |||
</syntaxhighlight> | |||
On an invoice-line extrafield, however, <code>$ID$</code> is the line ID, so this does not filter contacts by the parent invoice's third party. <code>__THIRDPARTY_ID__</code> is a template substitution token, not a placeholder supported by this extrafield-filter path. The parent third party is not directly exposed to this filter. | |||
==Load class for extrafields== | ==Load class for extrafields== | ||
To use extrafields all pages need include | To use extrafields all pages need include | ||
edit