[TYPO3-core] RFC: TS resolving of select fields with TCA hardcoded items
Ingmar Schlecht
ingmar at typo3.org
Fri Feb 10 10:08:27 CET 2006
Hey Christian,
Christian Jul Jensen wrote:
> + /**
> + * looks up the incoming value in the defined TCA configuration
> + *
> + * works only with TCA-type 'select' and options defined in 'items'
> + *
> + * @todo would be nice it this function basically looked up any type of value, db-relations etc
> + *
> + * @param mixed $inputValue commaseperated list of values to look up
> + * @param array $conf TS-configuration array
> + * Available options: table, the table to look up. field, the field that should be looked up. delimiter, optional delimiter string for multiple value output
> + * @return string returns the string of the translated values seperated by delimiter or, by default, comma. If no TCA items configurations is found, the valeu is just returned.
Small typo: "valeu" should be "value".
> + t3lib_div::loadTCA($table);
AFAIK, t3lib_div::loadTCA() doesn't work reliably in the frontend, for
example it doesn't properly get columns added as $tempColumns by extensions.
$GLOBALS['TSFE']->includeTCA(); does the job, but the downside is that
it always loads the FULL TCA.
> +
> + if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$field]) && is_array($TCA[$table]['columns'][$field]['config']['items'])) {
> + foreach ($values as $value) {
> + // Traverse the items-array...
> + reset($TCA[$table]['columns'][$field]['config']['items']);
> + while(list($key,$item)=each($TCA[$table]['columns'][$field]['config']['items'])) {
I'd change this reset/while/list/each construct to a foreach().
> + // ... and return the first found label where the value was equal to $key
One-line comments are usually indented with by one additional tab.
> + if (!strcmp($item[1],trim($value))) $output[] = $GLOBALS['TSFE']->sL($item[0]);
> + }
> +
> + }
> + return implode(($conf['delimiter']?$conf['delimiter']:' ,'),$output);
> + } else {
> + return $value;
> + }
> +
> + }
+1 if you change t3lib_div::loadTCA($table); to
$GLOBALS['TSFE']->includeTCA();.
See also:
http://typo3.org/documentation/mailing-lists/dev-list-archive/thread/110188767/
cheers,
Ingmar
More information about the TYPO3-team-core
mailing list