[TYPO3] Filling BE forms with dynamic data

Toby Cooper tac at pixelis.be
Mon Mar 27 14:05:58 CEST 2006


I found the answer, if anyone is interested you have to use the following : 

		'author' => Array (
			'exclude' => 1,
			'l10n_mode' => $l10n_mode_author,
			'label' =>
'LLL:EXT:lang/locallang_general.php:LGL.author',
			'config' => Array (
				'type' => 'user',
				'userFunc' => "user_getInfo->main",
			)

And the following (because type=> user doesn't create the input field) :

function main(&$params,&$pObj){
	$tmpname = '';	
	if ($GLOBALS['BE_USER']->user['realName'] != '') {
		$tmpname = $GLOBALS['BE_USER']->user['realName'];
	}
	return '<input
id="data[tt_news]['.$params['row']['uid'].'][author]_hr"
name="data[tt_news]['.$params['row']['uid'].'][author]_hr" maxlength="80"
value="'.$tmpname.'" size="30" />';
} 

Regards,

 
Toby Cooper

-----Original Message-----
From: typo3-english-bounces at lists.netfielders.de
[mailto:typo3-english-bounces at lists.netfielders.de] On Behalf Of Toby Cooper
Sent: mardi 14 mars 2006 23:57
To: typo3-english at lists.netfielders.de
Subject: [TYPO3] Filling BE forms with dynamic data

 
 
Hi there Typo friends, 
 
I've stumbled upon an issue I just can't seem to resolve.
 
I'm developping an extended news plugin for which I'm trying to 'autofill'
various input boxes in the BE insert news record form.
 
I can pull data from a table an send it to a dropdown list, and I can add an
arbitrary default value to an input box, but I can't seem to add dynamic
data to an input box. I've been through the core_doc_api and create
extension docs but just can't find the full answer.
 
Here is my own class file (class.user_getInfo.php) :
 
<?
 
class user_getInfo {
 
function main(&$params,&$pObj){
 
 
 
$params["items"] = array();
 
$params['items'][]=
array($GLOBALS['BE_USER']->user['username'],$GLOBALS['BE_USER']->user['usern
ame']);
}
 
}
?>
 
And here is my ext_tables file :
 
 
<?php
if (!defined ('TYPO3_MODE'))  die ('Access denied.');
 
if (TYPO3_MODE=="BE"){
include_once(t3lib_extMgm::extPath("pixnews")."class.user_getInfo.php");
 
}


t3lib_div::loadTCA("tt_news");
$tempColumns = Array (
  'author' => Array (
   'exclude' => 1,
   'l10n_mode' => $l10n_mode_author,
   'label' => 'LLL:EXT:lang/locallang_general.php:LGL.author',
   'config' => Array (
      "type" => "select", 
      "itemsProcFunc" => "user_getInfo->main",
      "items" => Array (
       Array("",0),
      ),
      "foreign_table" => "be_users", 
      "foreign_table_where" => "ORDER BY be_users.username", 
      "size" => 1, 
      "minitems" => 0,
      "maxitems" => 1,
   )
  ),


);
 
t3lib_extMgm::addTCAcolumns("tt_news",$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes("tt_news","");

...
 
?>
 
Now that works, ie it gives me a dropdown list with the current user
selected, but what I would really like to do is something like this :
 
<?
t3lib_div::loadTCA("tt_news");
$tempColumns = Array (
  'author' => Array (
   'exclude' => 1,
   'l10n_mode' => $l10n_mode_author,
   'label' => 'LLL:EXT:lang/locallang_general.php:LGL.author',
   'config' => Array (
     'type' => 'input',
    'size' => '20',
    'eval' => 'trim',
    'max' => '80',
    'default' => $this->user_getInfo->main,

    ),   
  ),


);
 
?>
 
because the following does work (on a new record only, not when editing an
previously created one, that alone took me 3 hours to figure out)
 
t3lib_div::loadTCA("tt_news");
$tempColumns = Array (
  'author' => Array (
   'exclude' => 1,
   'l10n_mode' => $l10n_mode_author,
   'label' => 'LLL:EXT:lang/locallang_general.php:LGL.author',
   'config' => Array (
     'type' => 'input',
    'size' => '20',
    'eval' => 'trim',
    'max' => '80',
    'default' => 'the dude',

    ),   
  ),


);
 
 
Any pointers would be welcome...
And an answer as to why I can't access $GLOBALS['BE_USER']->user['username']
directly from ext_tables.php would be nice too ...
 
Cheers, 
 
Toby Cooper
_______________________________________________
TYPO3-english mailing list
TYPO3-english at lists.netfielders.de
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-english




More information about the TYPO3-english mailing list