0009897.patch

Administrator Admin, 2008-12-04 16:57

Download (8.79 KB)

View differences:

t3lib/class.t3lib_extmgm.php (Arbeitskopie)
289 289
			if (is_array($types)) {
290 290
					// Iterate through all types and search for the field that defines the palette to be extended:
291 291
				foreach (array_keys($types) as $type) {
292
					$fields = self::getFieldsOfFieldList($types[$type]['showitem']);
293
					if (isset($fields[$field])) {
292
					$structure = self::getStructureOfItemList($types[$type]['showitem']);
293
					if (isset($structure['regularFields'][$field])) {
294
						$fieldReference =& $structure['regularFields'][$field];
294 295
							// If the field already has a palette, extend it:
295
						if ($fields[$field]['details']['palette']) {
296
							$palette = $fields[$field]['details']['palette'];
296
						if ($fieldReference['details']['palette']) {
297
							$palette = $fieldReference['details']['palette'];
297 298
							self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
298 299
							// If there's not palette yet, create one:
299 300
						} else {
......
303 304
								$palette = $generatedPalette = 'generatedFor-' . $field;
304 305
								self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
305 306
							}
306
							$fields[$field]['details']['palette'] = $palette;
307
							$types[$type]['showitem'] =  self::generateFieldList($fields);
307
							$fieldReference['details']['palette'] = $palette;
308
							$types[$type]['showitem'] =  self::generateItemList($structure['orderedItems']);
308 309
						}
309 310
					}
310 311
				}
......
368 369
			// Insert data before or after insertion points:
369 370
		} else {
370 371
			$positions = t3lib_div::trimExplode(',', $insertionPosition, true);
371
			$fields = self::getFieldsOfFieldList($list);
372
			$structure = self::getStructureOfItemList($list);
372 373
			$isInserted = false;
373 374
				// Iterate through all fields an check whether it's possible to inserte there:
374
			foreach ($fields as $field => &$fieldDetails) {
375
				$needles = self::getInsertionNeedles($field, $fieldDetails['details']);
376
					// Insert data before:
377
				foreach ($needles['before'] as $needle) {
378
					if (in_array($needle, $positions)) {
379
						$fieldDetails['rawData'] = $insertionList . ', '  . $fieldDetails['rawData'];
380
						$isInserted = true;
381
						break;
375
			foreach ($structure['orderedItems'] as &$itemDetails) {
376
				if ($itemDetails['details']['name']) {
377
					$needles = self::getInsertionNeedles($itemDetails['details']);
378
						// Insert data before:
379
					foreach ($needles['before'] as $needle) {
380
						if (in_array($needle, $positions)) {
381
							$itemDetails['rawData'] = $insertionList . ', '  . $itemDetails['rawData'];
382
							$isInserted = true;
383
							break;
384
						}
382 385
					}
383
				}
384
					// Insert data after:
385
				foreach ($needles['after'] as $needle) {
386
					if (in_array($needle, $positions)) {
387
						$fieldDetails['rawData'] .= ', ' . $insertionList;
388
						$isInserted = true;
386
						// Insert data after:
387
					foreach ($needles['after'] as $needle) {
388
						if (in_array($needle, $positions)) {
389
							$itemDetails['rawData'] .= ', ' . $insertionList;
390
							$isInserted = true;
391
							break;
392
						}
393
					}
394
						// Break if insertion was already done:
395
					if ($isInserted) {
389 396
						break;
390 397
					}
391 398
				}
392
					// Break if insertion was already done:
393
				if ($isInserted) {
394
					break;
395
				}
396 399
			}
397 400
				// If insertion point could not be determined, append the data:
398 401
			if (!$isInserted) {
399 402
				$list.= ($list ? ', ' : '') . $insertionList;
400 403
				// If data was correctly inserted before or after existing items, recreate the list:
401 404
			} else {
402
				$list = self::generateFieldList($fields, true);
405
				$list = self::generateItemList($structure['orderedItems'], true);
403 406
			}
404 407
		}
405 408

  
......
445 448
	 * Generates search needles that are used for inserting fields/items into an existing list.
446 449
	 *
447 450
	 * @see		executePositionedStringInsertion
448
	 * @param	string		$field: The name of the field/item
449
	 * @param	array		$fieldDetails: Additional details of the field like e.g. palette information
450
	 * 						(this array gets created by the function getFieldsOfFieldList())
451
	 * @param	array		$itemDetails: Additional details of the field/item like e.g. palette information
452
	 * 						(this gets created as sub-array by the function getStructureOfItemList())
451 453
	 * @return	array		The needled to be used for inserting content before or after existing fields/items
452 454
	 */
453
	protected static function getInsertionNeedles($field, array $fieldDetails) {
455
	protected static function getInsertionNeedles(array $itemDetails) {
456
		$itemName = $itemDetails['name'];
457

  
454 458
		$needles = array(
455
			'before' => array($field, 'before:' . $field),
456
			'after' => array('after:' . $field),
459
			'before' => array($itemName, 'before:' . $itemName),
460
			'after' => array('after:' . $itemName),
457 461
		);
458 462

  
459
		if ($fieldDetails['palette']) {
460
			$palette = $field . ';;' . $fieldDetails['palette'];
463
		if ($itemDetails['palette']) {
464
			$palette = $itemName . ';;' . $itemDetails['palette'];
461 465
			$needles['before'][] = $palette;
462 466
			$needles['before'][] = 'before:' . $palette;
463 467
			$needles['afer'][] = 'after:' . $palette;
......
467 471
	}
468 472

  
469 473
	/**
470
	 * Generates an array of fields with additional information such as e.g. the name of the palette.
474
	 * Generates an array of fields/items with additional information such as e.g. the name of the palette.
471 475
	 *
472
	 * @param	string		$fieldList: List of fields/items to be splitted up
476
	 * @param	string		$itemList: List of fields/items to be splitted up
473 477
	 * 						(this mostly reflects the data in $TCA[<table>]['types'][<type>]['showitem'])
474
	 * @return	array		An array with the names of the fields as keys and additional information
478
	 * @return	array		An array multidimensional array with the main keys 'orderedItems' and 'regularFields'
475 479
	 */
476
	protected static function getFieldsOfFieldList($fieldList) {
477
		$fields = array();
478
		$fieldParts = t3lib_div::trimExplode(',', $fieldList, true);
480
	protected static function getStructureOfItemList($itemList) {
481
		$structure = array(
482
			'orderedItems' => array(),
483
			'regularFields' => array(),
484
		);
479 485

  
480
		foreach ($fieldParts as $fieldPart) {
481
			$fieldDetails = t3lib_div::trimExplode(';', $fieldPart, false, 5);
482
			if (!isset($fields[$fieldDetails[0]])) {
483
				$fields[$fieldDetails[0]] = array(
484
					'rawData' => $fieldPart,
485
					'details' => array(
486
						'field' => $fieldDetails[0],
487
						'label' => $fieldDetails[1],
488
						'palette' => $fieldDetails[2],
489
						'special' => $fieldDetails[3],
490
						'styles' => $fieldDetails[4],
491
					),
492
				);
486
		$itemParts = t3lib_div::trimExplode(',', $itemList, true);
487

  
488
		foreach ($itemParts as $index => $itemPart) {
489
			$itemDetails = t3lib_div::trimExplode(';', $itemPart, false, 5);
490
				// Add definition of current item in the order it appeared in the field list:
491
			$structure['orderedItems'][$index] = array(
492
				'rawData' => $itemPart,
493
				'details' => array(
494
					'name' => $itemDetails[0],
495
					'label' => $itemDetails[1],
496
					'palette' => $itemDetails[2],
497
					'special' => $itemDetails[3],
498
					'styles' => $itemDetails[4],
499
				),
500
			);
501
				// Set reference for regular fields (no --div-- or --palette--):
502
			if (!isset($structure['regularFields'][$itemDetails[0]]) && strpos($itemDetails[0], '--') === false) {
503
				$structure['regularFields'][$itemDetails[0]] =& $structure['orderedItems'][$index]; 
493 504
			}
494 505
		}
495 506

  
496
		return $fields;
507
		return $structure;
497 508
	}
498 509

  
499 510
	/**
500 511
	 * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
501 512
	 *
502
	 * @see		getFieldsOfFieldList
503
	 * @param	array		$fields: The array of fields with optional additional information
513
	 * @see		getStructureOfItemList
514
	 * @param	array		$orderedItems: The array of ordered items with optional additional information
504 515
	 * @param	boolean		$useRawData: Use raw data instead of building by using the details (default: false)
505 516
	 * @return	string		The list of fields/items which gets used for $TCA[<table>]['types'][<type>]['showitem']
506 517
	 * 						or $TCA[<table>]['palettes'][<palette>]['showitem'] in most cases
507 518
	 */
508
	protected static function generateFieldList(array $fields, $useRawData = false) {
509
		$fieldParts = array();
519
	protected static function generateItemList(array $orderedItems, $useRawData = false) {
520
		$itemParts = array();
510 521

  
511
		foreach ($fields as $field => $fieldDetails) {
522
		foreach ($orderedItems as $itemName => $itemDetails) {
512 523
			if ($useRawData) {
513
				$fieldParts[] = $fieldDetails['rawData'];
524
				$itemParts[] = $itemDetails['rawData'];
514 525
			} else {
515
				$fieldParts[] = (count($fieldDetails['details']) > 1 ? implode(';', $fieldDetails['details']) : $field);
526
				$itemParts[] = (count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $itemName);
516 527
			}
517 528
		}
518 529

  
519
		return implode(', ', $fieldParts);
530
		return implode(', ', $itemParts);
520 531
	}
521 532

  
522 533
	/**