0011834_v2_ws.patch

Administrator Admin, 2009-08-31 19:39

Download (3.41 KB)

View differences:

t3lib/class.t3lib_extmgm.php (Arbeitskopie)
308 308
	 */
309 309
	public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
310 310
		$generatedPalette = '';
311
		$processedPalettes = array();
311 312
		t3lib_div::loadTCA($table);
312 313

  
313 314
		if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
......
320 321
							// If the field already has a palette, extend it:
321 322
						if ($items[$field]['details']['palette']) {
322 323
							$palette = $items[$field]['details']['palette'];
324
							if (!isset($processedPalettes[$palette])) {
323 325
							self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
326
								$processedPalettes[$palette] = true;
327
							}
324 328
							// If there's not palette yet, create one:
325 329
						} else {
326 330
							if ($generatedPalette) {
......
366 370
				);
367 371
				// If it's a new palette, just set the data:
368 372
			} else {
369
				$paletteData['showitem'] = $addFields;
373
				$paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
370 374
			}
371 375
		}
372 376
	}
......
386 390
	 */
387 391
	protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
388 392
		$list = trim($list);
389
		$insertionList = self::removeDuplicatesForInsertion($list, $insertionList);
393
		$insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
390 394

  
395
		if ($insertionList) {
391 396
			// Append data to the end (default):
392 397
		if ($insertionPosition === '') {
393 398
			$list.= ($list ? ', ' : '') . $insertionList;
......
428 433
				$list = self::generateItemList($items, true);
429 434
			}
430 435
		}
436
		}
431 437

  
432 438
		return $list;
433 439
	}
......
441 447
	 *  + insertion: 'field_b, field_d, field_c;;;4-4-4'
442 448
	 * -> new insertion: 'field_d'
443 449
	 *
444
	 * @param	string		$list: The list of items to be extended
445 450
	 * @param	string		$insertionList: The list of items to inserted
451
	 * @param	string		$list: The list of items to be extended (default: '')
446 452
	 * @return	string		Duplicate-free list of items to be inserted
447 453
	 */
448
	protected static function removeDuplicatesForInsertion($list, $insertionList) {
454
	protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
449 455
		$pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
456
		$listItems = array();
450 457

  
451 458
		if ($list && preg_match_all($pattern, $list, $listMatches)) {
459
			$listItems = $listMatches[2];
460
		}
461

  
452 462
			if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
453
				$duplicates = array_intersect($listMatches[2], $insertionListMatches[2]);
454
				if ($duplicates) {
455
					foreach ($duplicates as &$duplicate) {
456
						$duplicate = preg_quote($duplicate, '/');
463
			$insertionItems = array();
464
			$insertionDuplicates = false;
465

  
466
			foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
467
				if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
468
					$insertionItems[$insertionItem] = true;
469
				} else {
470
					unset($insertionListMatches[0][$insertionIndex]);
471
					$insertionDuplicates = true;
457 472
					}
458
					$insertionList = preg_replace(
459
						array('/(^|,)\s*\b(' . implode('|', $duplicates) . ')\b[^,]*(,|$)/', '/,$/'),
460
						array('\3', ''),
461
						$insertionList
462
					);
463 473
				}
474

  
475
			if ($insertionDuplicates) {
476
				$insertionList = implode('', $insertionListMatches[0]);
464 477
			}
465 478
		}
466 479