typo3-6.1.1-displayCond.patch

David Frerich, 2013-07-02 15:21

Download (4.92 KB)

View differences:

typo3_src-6.1.1-patched//typo3/sysext/backend/Classes/Form/ElementConditionMatcher.php 2013-07-02 14:49:22.000000000 +0200
42 42
	 * @var array
43 43
	 */
44 44
	protected $record = array();
45
	
46
	/**
47
	 * @var string
48
	 */
49
	protected $recordTable = '';
45 50

  
46 51
	/**
47 52
	 * Evaluates the provided condition and returns TRUE if the form
......
113 118
		}
114 119
		return $result;
115 120
	}
121
	
122
	/**
123
	 * @param string $recordTable
124
	 * @return ElementConditionMatcher
125
	 */
126
	public function setRecordTable($recordTable)
127
	{
128
		$this->recordTable = $recordTable;
129
		
130
		return $this;
131
	}
116 132

  
117 133
	/**
118 134
	 * Evaluates the provided condition and returns TRUE if the form
......
176 192
		}
177 193
		return $result;
178 194
	}
195
	
196
	/**
197
	 * @param string $fieldName
198
	 * @param array $record
199
	 * @return string
200
	 */
201
	protected function getRecordFieldValue($fieldName, $record, $recordTable = '')
202
	{
203
		if (strpos($fieldName, '.') !== false) {
204
			$fieldValue = null;
205
			
206
			$fieldNameParts = explode('.', $fieldName, 2);
207
			$parentFieldName = $fieldNameParts[0];
208
			$subFieldName = $fieldNameParts[1];
209
			
210
			if (array_key_exists($parentFieldName, $record) && $record[$parentFieldName]) {
211
				$recordFieldValue = $record[$parentFieldName];
212

  
213
				if ($recordTable) {
214
					$fieldTCA = $GLOBALS['TCA'][$recordTable]['columns'][$parentFieldName];
215

  
216
					$subRecordTable = '';
217
					$subRecordUid = 0;
218
					switch ($fieldTCA['config']['type']) {
219
						case 'select':
220
							break;
221
						case 'group':
222
							if ($fieldTCA['config']['internal_type'] == 'db') {
223
								$recordFieldValues = explode(',', $recordFieldValue);
224
								$allowedTables = array_map('trim', explode(',', $fieldTCA['config']['allowed']));
225
	
226
								if (count($allowedTables) === 1 || is_numeric($recordFieldValues)) {
227
									$subRecordTable = array_shift($allowedTables);
228
								} else {
229
									foreach ($allowedTables as $table) {
230
										if (strpos($recordFieldValues[0], $table) === 0) {
231
											$subRecordTable = $table;
232
											break;
233
										}
234
									}
235
								}
236
	
237
								$subRecordUid = (int)array_shift(explode('|', str_replace($subRecordTable . '_', '', $recordFieldValue)));
238
							}
239
							break;
240
						case 'inline':
241
							break;
242
					}
243
					
244
					if ($subRecordTable && $subRecordUid) {
245
						$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $subRecordTable, 'uid=' . $subRecordUid . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($subRecordTable));
246
						$subRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
247
						$GLOBALS['TYPO3_DB']->sql_free_result($res);
248
						
249
						if ($subRecord) {
250
							\TYPO3\CMS\Backend\Utility\BackendUtility::fixVersioningPid($subRecordTable, $subRecord);
251
							$fieldValue = $this->getRecordFieldValue($subFieldName, $subRecord, $subRecordTable);
252
						}
253
					}
254
				}
255
			}
256
		} else {
257
			$fieldValue = $record[$fieldName];
258
		}
259
		
260
		return $fieldValue;
261
	}
179 262

  
180 263
	/**
181 264
	 * Evaluates conditions concerning a field of the current record.
......
197 280
				$fieldValue = $this->record[$fieldName][$this->flexformValueKey];
198 281
			}
199 282
		} else {
200
			$fieldValue = $this->record[$fieldName];
283
			$fieldValue = $this->getRecordFieldValue($fieldName, $this->record, $this->recordTable);
201 284
		}
202 285

  
203 286
		$result = FALSE;
typo3_src-6.1.1-patched//typo3/sysext/backend/Classes/Form/FormEngine.php 2013-07-02 13:53:07.000000000 +0200
1007 1007
		if (is_array($PA['fieldConf']) && $PA['fieldConf']['displayCond'] && is_array($row)) {
1008 1008
			/** @var $elementConditionMatcher \TYPO3\CMS\Backend\Form\ElementConditionMatcher */
1009 1009
			$elementConditionMatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\ElementConditionMatcher');
1010
			$elementConditionMatcher->setRecordTable($table);
1010 1011
			$displayConditionResult = $elementConditionMatcher->match($PA['fieldConf']['displayCond'], $row);
1011 1012
		}
1012 1013

  
......
2934 2935

  
2935 2936
						/** @var $elementConditionMatcher \TYPO3\CMS\Backend\Form\ElementConditionMatcher */
2936 2937
						$elementConditionMatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\ElementConditionMatcher');
2938
						$elementConditionMatcher->setRecordTable($table);
2937 2939

  
2938 2940
						foreach ($rotateLang as $vDEFkey) {
2939 2941
							$vDEFkey = 'v' . $vDEFkey;