[Typo3-dev] Eval of TCA field with JavaScript

Thomas Hempel thomas at scriptme.de
Fri Apr 1 09:25:02 CEST 2005


Hi Andreas,

The hook is allready there!
Have a look into the class.t3lib_tcemain.php (Line 436 to 441)

Here is my method that is called there:

function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$this) {
	// Do only if our extension is processed and if the dataset is updated
	// and a datastructure is submitted (Flexform has changed)
	if ($table == 'tx_flextest_flextests' && $status == 'update' && isset($fieldArray['datastructure'])) {

		// The check of the input fields is hardcoded what is not so nice but
		// I found no other solution until now. If anybody has a suggestion
		// or a tip, feel free to contact me.

		// get the orginal data from the transmitted field
		$orgData = t3lib_div::xml2array($fieldArray['datastructure']);
		$data = $orgData['data']['sDEF']['lDEF'];

		// create an empty array that holds all elements that where allready
		// used in a field before
		$existingItems = array();
	
		// cycle through all flexform fields on the first sheet (sDEF)
		foreach ($data as $elKey => $element) {
			// extract the list of assigned elements
			$localItems = explode(',', $element['vDEF']);
			// create an empty array, this is used for building up a valid list
			$newLocalItems = array();

			// now check every item in the list
			foreach ($localItems as $key => $itemUid) {
				// if the item is not used yet...
				if (!in_array($itemUid, $existingItems) && $itemUid != '') {
					// ... add it to the new list and the global item list
					$existingItems[] = $itemUid;
					$newLocalItems[] = $itemUid;
				}
			}

			// make a comma separated list from the array
			$newLocalItems = implode(',', $newLocalItems);
			// and write it back to the extracted data
			$data[$elKey]['vDEF'] = $newLocalItems;
		}

		// now write the modified data back to the fieldArray
		$orgData['data']['sDEF']['lDEF'] = $data;
		$fieldArray['datastructure'] = t3lib_div::array2xml($orgData, '', 0, 'T3DataStructure');

		// at this point anything is done. Because the fieldArray is a reference
		// We don't have to return something. We just let the things going their
		// way...
	}
}

I don't know if this is the way it should beimplemented but it works.


Greets,
Thomas




More information about the TYPO3-dev mailing list