Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v10 here: TYPO3 ELTS.
foreign_table_where
foreign_table_where
-
- Type
- string (SQL WHERE)
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']
- Scope
- Proc. / Display
- RenderType
- all
The items from foreign_table are selected with this
WHERE
clause. TheWHERE
clause is effectively appended to the existingWHERE
clause (which contains default constraints, such asNOT deleted
) and must begin withAND
.
Field quoting
The example below uses the special field quoting syntax {#...}
around identifiers of the
QueryHelper
to be as DBAL compatible as possible. Note that ORDER BY
and GROUP BY
should NOT be quoted, since they always receive proper quoting automatically
through the API.
Markers inside the WHERE statement
It is possible to use markers in the WHERE clause:
- ###REC_FIELD_[field name]###
-
Any field of the current record.
Note
The field name part of the marker is not in upper case letters. It must match the exact case used in the database.
So for example
sys_
must be referenced usinglanguage_ uid ###REC_
FIELD_ sys_ language_ uid### - ###THIS_UID###
- Current element uid (zero if new).
- ###CURRENT_PID###
- The current page id (pid of the record).
###SITEROOT###
- ###PAGE_TSCONFIG_ID###
- A value you can set from Page TSconfig dynamically.
- ###PAGE_TSCONFIG_IDLIST###
- A value you can set from Page TSconfig dynamically.
- ###PAGE_TSCONFIG_STR###
- A value you can set from Page TSconfig dynamically.
- ###SITE:<KEY>.<SUBKEY>###
- A value from the site configuration, for example:
###SITE:
ormy Setting. category Pid### ###SITE:
.root Page Id###
The markers are preprocessed so that the value of CURRENT_PID and PAGE_TSCONFIG_ID are always integers (default is zero), PAGE_TSCONFIG_IDLIST will always be a comma-separated list of integers (default is zero) and PAGE_TSCONFIG_STR will be quoted before substitution (default is blank string).
More information about markers set by Page TSconfig can be found in the TSconfig reference.
Examples
Select single field with foreign_prefix and foreign_where
[
'columns' => [
'select_single_3' => [
'exclude' => 1,
'label' => 'select_single_3 static values, dividers, foreign_table_where',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'Static values',
'--div--',
],
[
'static -2',
-2,
],
[
'static -1',
-1,
],
[
'DB values',
'--div--',
],
],
'foreign_table' => 'tx_styleguide_staticdata',
'foreign_table_where' => 'AND {#tx_styleguide_staticdata}.{#value_1} LIKE \'%foo%\' ORDER BY uid',
'foreign_table_prefix' => 'A prefix: ',
],
],
],
]
Tree field with foreign_table_where
[
'columns' => [
'select_tree_6' => [
'exclude' => 1,
'label' => 'select_tree_6 categories',
'config' => [
'type' => 'select',
'renderType' => 'selectTree',
'foreign_table' => 'sys_category',
'foreign_table_where' => 'AND ({#sys_category}.{#sys_language_uid} = 0 OR {#sys_category}.{#l10n_parent} = 0) ORDER BY sys_category.sorting',
'size' => 20,
'treeConfig' => [
'parentField' => 'parent',
'appearance' => [
'expandAll' => true,
'showHeader' => true,
],
],
],
],
],
]