@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $output[$this->getFieldName()] = $value; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $output['DT_RowId'] = 'row-' . $object->getUid(); |
|
| 129 | + $output['DT_RowId'] = 'row-'.$object->getUid(); |
|
| 130 | 130 | $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid()); |
| 131 | 131 | |
| 132 | 132 | return $output; |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | foreach ($localizedStructure as $index => $structure) { |
| 328 | 328 | |
| 329 | 329 | $localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>', |
| 330 | - empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 330 | + empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-'.$structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 331 | 331 | $structure['value'] |
| 332 | 332 | ); |
| 333 | 333 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime'); |
| 353 | 353 | foreach ($enablesMethods as $enableMethod) { |
| 354 | 354 | |
| 355 | - $methodName = 'get' . $enableMethod . 'Field'; |
|
| 355 | + $methodName = 'get'.$enableMethod.'Field'; |
|
| 356 | 356 | |
| 357 | 357 | // Fetch possible hidden filed. |
| 358 | 358 | $enableField = Tca::table($object)->$methodName(); |
@@ -26,628 +26,628 @@ |
||
| 26 | 26 | class Row extends AbstractComponentView |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $columns = []; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Registry for storing variable values and speed up the processing. |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $variables = []; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param array $columns |
|
| 43 | - */ |
|
| 44 | - public function __construct(array $columns = []) |
|
| 45 | - { |
|
| 46 | - $this->columns = $columns; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Render a row to be displayed in the Grid given an Content Object. |
|
| 51 | - * |
|
| 52 | - * @param Content $object |
|
| 53 | - * @param int $rowIndex |
|
| 54 | - * @return array |
|
| 55 | - * @throws \Exception |
|
| 56 | - */ |
|
| 57 | - public function render(Content $object = null, $rowIndex = 0) |
|
| 58 | - { |
|
| 59 | - |
|
| 60 | - // Initialize returned array |
|
| 61 | - $output = []; |
|
| 62 | - |
|
| 63 | - foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) { |
|
| 64 | - |
|
| 65 | - $value = ''; // default is empty at first. |
|
| 66 | - |
|
| 67 | - $this->computeVariables($object, $fieldNameAndPath); |
|
| 68 | - |
|
| 69 | - // Only compute the value if it is going to be shown in the Grid. Lost of time otherwise! |
|
| 70 | - if (in_array($fieldNameAndPath, $this->columns)) { |
|
| 71 | - |
|
| 72 | - // Fetch value |
|
| 73 | - if (Tca::grid()->hasRenderers($fieldNameAndPath)) { |
|
| 74 | - |
|
| 75 | - $value = ''; |
|
| 76 | - $renderers = Tca::grid()->getRenderers($fieldNameAndPath); |
|
| 77 | - |
|
| 78 | - // if is relation has one |
|
| 79 | - foreach ($renderers as $rendererClassName => $rendererConfiguration) { |
|
| 80 | - |
|
| 81 | - /** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */ |
|
| 82 | - $rendererObject = GeneralUtility::makeInstance($rendererClassName); |
|
| 83 | - $value .= $rendererObject |
|
| 84 | - ->setObject($object) |
|
| 85 | - ->setFieldName($fieldNameAndPath) |
|
| 86 | - ->setRowIndex($rowIndex) |
|
| 87 | - ->setFieldConfiguration($configuration) |
|
| 88 | - ->setGridRendererConfiguration($rendererConfiguration) |
|
| 89 | - ->render(); |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - $value = $this->resolveValue($object, $fieldNameAndPath); |
|
| 93 | - $value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing. |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Possible formatting given by configuration. @see TCA['grid'] |
|
| 97 | - $value = $this->formatValue($value, $configuration); |
|
| 98 | - |
|
| 99 | - // Here, there is the chance to further "decorate" the value for inline editing, localization, ... |
|
| 100 | - if ($this->willBeEnriched()) { |
|
| 101 | - |
|
| 102 | - $localizedStructure = $this->initializeLocalizedStructure($value); |
|
| 103 | - |
|
| 104 | - if ($this->isEditable()) { |
|
| 105 | - $localizedStructure = $this->addEditableMarkup($localizedStructure); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($this->isLocalized()) { |
|
| 109 | - $localizedStructure = $this->addLocalizationMarkup($localizedStructure); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if ($this->hasIcon()) { |
|
| 113 | - $localizedStructure = $this->addSpriteIconMarkup($localizedStructure); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $value = $this->flattenStructure($localizedStructure); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Final wrap given by configuration. @see TCA['grid'] |
|
| 120 | - $value = $this->wrapValue($value, $configuration); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $output[$this->getFieldName()] = $value; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $output['DT_RowId'] = 'row-' . $object->getUid(); |
|
| 127 | - $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid()); |
|
| 128 | - |
|
| 129 | - return $output; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Flatten the localized structure to render the final value |
|
| 134 | - * |
|
| 135 | - * @param array $localizedStructure |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - protected function flattenStructure(array $localizedStructure) |
|
| 139 | - { |
|
| 140 | - |
|
| 141 | - // Flatten the structure. |
|
| 142 | - $value = ''; |
|
| 143 | - foreach ($localizedStructure as $structure) { |
|
| 144 | - $value .= sprintf('<div class="%s">%s</div>', |
|
| 145 | - $structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '', |
|
| 146 | - $structure['value'] |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - return $value; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Store some often used variable values and speed up the processing. |
|
| 154 | - * |
|
| 155 | - * @param Content $object |
|
| 156 | - * @param string $fieldNameAndPath |
|
| 157 | - * @return void |
|
| 158 | - */ |
|
| 159 | - protected function computeVariables(Content $object, $fieldNameAndPath) |
|
| 160 | - { |
|
| 161 | - $this->variables = []; |
|
| 162 | - $this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
| 163 | - $this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 164 | - $this->variables['fieldNameAndPath'] = $fieldNameAndPath; |
|
| 165 | - $this->variables['object'] = $object; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Tell whether the object will be decorated / wrapped such as |
|
| 170 | - * |
|
| 171 | - * @param string $value |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - protected function initializeLocalizedStructure($value) |
|
| 175 | - { |
|
| 176 | - |
|
| 177 | - $localizedStructure[] = [ |
|
| 178 | - 'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value, |
|
| 179 | - 'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED, |
|
| 180 | - 'language' => 0, |
|
| 181 | - 'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(), |
|
| 182 | - ]; |
|
| 183 | - |
|
| 184 | - if ($this->isLocalized()) { |
|
| 185 | - |
|
| 186 | - foreach ($this->getLanguageService()->getLanguages() as $language) { |
|
| 187 | - |
|
| 188 | - // Make sure the language is allowed for the current Backend User. |
|
| 189 | - if ($this->isLanguageAllowedForBackendUser($language)) { |
|
| 190 | - |
|
| 191 | - $resolvedObject = $this->getResolvedObject(); |
|
| 192 | - $fieldName = $this->getFieldName(); |
|
| 193 | - |
|
| 194 | - if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) { |
|
| 195 | - $localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName); |
|
| 196 | - $status = LocalizationStatus::LOCALIZED; |
|
| 197 | - |
|
| 198 | - // Replace blank value by something more meaningful for the End User. |
|
| 199 | - if (empty($localizedValue)) { |
|
| 200 | - $status = LocalizationStatus::EMPTY_VALUE; |
|
| 201 | - $localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : ''; |
|
| 202 | - } |
|
| 203 | - } else { |
|
| 204 | - $localizedValue = sprintf('<a href="%s" style="color: black">%s</a>', |
|
| 205 | - $this->getLocalizedUri($language['uid']), |
|
| 206 | - $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation') |
|
| 207 | - ); |
|
| 208 | - $status = LocalizationStatus::NOT_YET_LOCALIZED; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // Feed structure. |
|
| 212 | - $localizedStructure[] = [ |
|
| 213 | - 'value' => $localizedValue, |
|
| 214 | - 'status' => $status, |
|
| 215 | - 'language' => (int)$language['uid'], |
|
| 216 | - 'languageFlag' => $language['flag'], |
|
| 217 | - ]; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return $localizedStructure; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param array $language |
|
| 227 | - * @return bool |
|
| 228 | - */ |
|
| 229 | - protected function isLanguageAllowedForBackendUser(array $language) |
|
| 230 | - { |
|
| 231 | - return $this->getBackendUser()->checkLanguageAccess($language['uid']); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Returns a placeholder when the value is empty. |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - protected function getEmptyValuePlaceholder() |
|
| 240 | - { |
|
| 241 | - return sprintf('<i>%s</i>', |
|
| 242 | - $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing') |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose. |
|
| 248 | - * |
|
| 249 | - * @return bool |
|
| 250 | - */ |
|
| 251 | - protected function willBeEnriched() |
|
| 252 | - { |
|
| 253 | - |
|
| 254 | - $willBeEnriched = false; |
|
| 255 | - |
|
| 256 | - if ($this->fieldExists()) { |
|
| 257 | - $willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $willBeEnriched; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Tell whether the field in the context will be prepended by an icon. |
|
| 265 | - * |
|
| 266 | - * @return bool |
|
| 267 | - */ |
|
| 268 | - protected function hasIcon() |
|
| 269 | - { |
|
| 270 | - $dataType = $this->getDataType(); |
|
| 271 | - return Tca::table($dataType)->getLabelField() === $this->getFieldName(); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Tell whether the field in the context will be prepended by an icon. |
|
| 276 | - * |
|
| 277 | - * @return bool |
|
| 278 | - */ |
|
| 279 | - protected function isLocalized() |
|
| 280 | - { |
|
| 281 | - $object = $this->getObject(); |
|
| 282 | - $fieldName = $this->getFieldName(); |
|
| 283 | - $dataType = $this->getDataType(); |
|
| 284 | - $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 285 | - |
|
| 286 | - return $this->getLanguageService()->hasLanguages() |
|
| 287 | - && Tca::grid($object)->isLocalized($fieldNameAndPath) |
|
| 288 | - && Tca::table($dataType)->field($fieldName)->isLocalized(); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Add some markup to have the content editable in the Grid. |
|
| 293 | - * |
|
| 294 | - * @param array $localizedStructure |
|
| 295 | - * @return array |
|
| 296 | - */ |
|
| 297 | - protected function addEditableMarkup(array $localizedStructure) |
|
| 298 | - { |
|
| 299 | - |
|
| 300 | - $dataType = $this->getDataType(); |
|
| 301 | - $fieldName = $this->getFieldName(); |
|
| 302 | - |
|
| 303 | - foreach ($localizedStructure as $index => $structure) { |
|
| 304 | - if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) { |
|
| 305 | - $localizedStructure[$index]['value'] = sprintf('<span class="%s" data-language="%s">%s</span>', |
|
| 306 | - Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield', |
|
| 307 | - $structure['language'], |
|
| 308 | - $structure['value'] |
|
| 309 | - ); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - return $localizedStructure; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Add some markup related to the localization. |
|
| 317 | - * |
|
| 318 | - * @param array $localizedStructure |
|
| 319 | - * @return array |
|
| 320 | - */ |
|
| 321 | - protected function addLocalizationMarkup(array $localizedStructure) |
|
| 322 | - { |
|
| 323 | - |
|
| 324 | - foreach ($localizedStructure as $index => $structure) { |
|
| 325 | - |
|
| 326 | - $localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>', |
|
| 327 | - empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 328 | - $structure['value'] |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - return $localizedStructure; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Add some markup related to the prepended icon. |
|
| 336 | - * |
|
| 337 | - * @param array $localizedStructure |
|
| 338 | - * @return array |
|
| 339 | - */ |
|
| 340 | - protected function addSpriteIconMarkup(array $localizedStructure) |
|
| 341 | - { |
|
| 342 | - |
|
| 343 | - $object = $this->getObject(); |
|
| 344 | - |
|
| 345 | - foreach ($localizedStructure as $index => $structure) { |
|
| 346 | - |
|
| 347 | - $recordData = []; |
|
| 348 | - |
|
| 349 | - $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime'); |
|
| 350 | - foreach ($enablesMethods as $enableMethod) { |
|
| 351 | - |
|
| 352 | - $methodName = 'get' . $enableMethod . 'Field'; |
|
| 353 | - |
|
| 354 | - // Fetch possible hidden filed. |
|
| 355 | - $enableField = Tca::table($object)->$methodName(); |
|
| 356 | - if ($enableField) { |
|
| 357 | - $recordData[$enableField] = $object[$enableField]; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - // Get Enable Fields of the object to render the sprite with overlays. |
|
| 362 | - $localizedStructure[$index]['value'] = sprintf('%s %s', |
|
| 363 | - $this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL), |
|
| 364 | - $structure['value'] |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $localizedStructure; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Return whether the field given by the context is editable. |
|
| 373 | - * |
|
| 374 | - * @return boolean |
|
| 375 | - */ |
|
| 376 | - protected function isEditable() |
|
| 377 | - { |
|
| 378 | - $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 379 | - $dataType = $this->getDataType(); |
|
| 380 | - $fieldName = $this->getFieldName(); |
|
| 381 | - |
|
| 382 | - return Tca::grid()->isEditable($fieldNameAndPath) |
|
| 383 | - && Tca::table($dataType)->hasField($fieldName) |
|
| 384 | - && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only. |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Return the appropriate URI to create the translation. |
|
| 389 | - * |
|
| 390 | - * @param int $language |
|
| 391 | - * @return string |
|
| 392 | - */ |
|
| 393 | - protected function getLocalizedUri($language) |
|
| 394 | - { |
|
| 395 | - |
|
| 396 | - // Transmit recursive selection parameter. |
|
| 397 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
| 398 | - $parameters = GeneralUtility::_GP($parameterPrefix); |
|
| 399 | - |
|
| 400 | - $additionalParameters = array( |
|
| 401 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 402 | - 'controller' => 'Content', |
|
| 403 | - 'action' => 'localize', |
|
| 404 | - 'format' => 'json', |
|
| 405 | - 'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0, |
|
| 406 | - 'fieldNameAndPath' => $this->getFieldNameAndPath(), |
|
| 407 | - 'language' => $language, |
|
| 408 | - 'matches' => array( |
|
| 409 | - 'uid' => $this->getObject()->getUid(), |
|
| 410 | - ), |
|
| 411 | - ), |
|
| 412 | - ); |
|
| 413 | - |
|
| 414 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Compute the value for the Content object according to a field name. |
|
| 419 | - * |
|
| 420 | - * @param Content $object |
|
| 421 | - * @param string $fieldNameAndPath |
|
| 422 | - * @return string |
|
| 423 | - */ |
|
| 424 | - protected function resolveValue(Content $object, $fieldNameAndPath) |
|
| 425 | - { |
|
| 426 | - |
|
| 427 | - // Get the first part of the field name and |
|
| 428 | - $fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath); |
|
| 429 | - |
|
| 430 | - $value = $object[$fieldName]; |
|
| 431 | - |
|
| 432 | - // Relation but contains no data. |
|
| 433 | - if (is_array($value) && empty($value)) { |
|
| 434 | - $value = ''; |
|
| 435 | - } elseif ($value instanceof Content) { |
|
| 436 | - |
|
| 437 | - $fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 438 | - |
|
| 439 | - // true means the field name does not contains a path. "title" vs "metadata.title" |
|
| 440 | - // Fetch the default label |
|
| 441 | - if ($fieldNameOfForeignTable === $fieldName) { |
|
| 442 | - $foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable(); |
|
| 443 | - $fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField(); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - $value = $object[$fieldName][$fieldNameOfForeignTable]; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - return $value; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Check whether a string contains HTML tags. |
|
| 454 | - * |
|
| 455 | - * @param string $string the content to be analyzed |
|
| 456 | - * @return boolean |
|
| 457 | - */ |
|
| 458 | - protected function hasHtml($string) |
|
| 459 | - { |
|
| 460 | - $result = false; |
|
| 461 | - |
|
| 462 | - // We compare the length of the string with html tags and without html tags. |
|
| 463 | - if (strlen($string) !== strlen(strip_tags($string))) { |
|
| 464 | - $result = true; |
|
| 465 | - } |
|
| 466 | - return $result; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Check whether a string contains potential XSS. |
|
| 471 | - * |
|
| 472 | - * @param string $string the content to be analyzed |
|
| 473 | - * @return boolean |
|
| 474 | - */ |
|
| 475 | - protected function isClean($string) |
|
| 476 | - { |
|
| 477 | - |
|
| 478 | - // @todo implement me! |
|
| 479 | - $result = true; |
|
| 480 | - return $result; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Process the value |
|
| 485 | - * |
|
| 486 | - * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however! |
|
| 487 | - * e.g DefaultValueGridProcessor, TextAreaGridProcessor, ... |
|
| 488 | - * |
|
| 489 | - * @param string $value |
|
| 490 | - * @param Content $object |
|
| 491 | - * @param string $fieldNameAndPath |
|
| 492 | - * @return string |
|
| 493 | - * @throws InvalidKeyInArrayException |
|
| 494 | - */ |
|
| 495 | - protected function processValue($value, Content $object, $fieldNameAndPath) |
|
| 496 | - { |
|
| 497 | - |
|
| 498 | - // Set default value if $field name correspond to the label of the table |
|
| 499 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 500 | - if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) { |
|
| 501 | - $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title')); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - // Sanitize the value in case of "select" or "radio button". |
|
| 505 | - if (is_scalar($value)) { |
|
| 506 | - $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType(); |
|
| 507 | - if ($fieldType !== FieldType::TEXTAREA) { |
|
| 508 | - $value = htmlspecialchars($value); |
|
| 509 | - } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) { |
|
| 510 | - $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML. |
|
| 511 | - } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) { |
|
| 512 | - $value = nl2br($value); |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return $value; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Possible value formatting. |
|
| 521 | - * |
|
| 522 | - * @param string $value |
|
| 523 | - * @param array $configuration |
|
| 524 | - * @return string |
|
| 525 | - * @throws \InvalidArgumentException |
|
| 526 | - */ |
|
| 527 | - protected function formatValue($value, array $configuration) |
|
| 528 | - { |
|
| 529 | - if (empty($configuration['format'])) { |
|
| 530 | - return $value; |
|
| 531 | - } |
|
| 532 | - $className = $configuration['format']; |
|
| 533 | - |
|
| 534 | - /** @var FormatterInterface $formatter */ |
|
| 535 | - $formatter = GeneralUtility::makeInstance($className); |
|
| 536 | - $value = $formatter->format($value); |
|
| 537 | - |
|
| 538 | - return $value; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Possible value wrapping. |
|
| 543 | - * |
|
| 544 | - * @param string $value |
|
| 545 | - * @param array $configuration |
|
| 546 | - * @return string |
|
| 547 | - */ |
|
| 548 | - protected function wrapValue($value, array $configuration) |
|
| 549 | - { |
|
| 550 | - if (!empty($configuration['wrap'])) { |
|
| 551 | - $parts = explode('|', $configuration['wrap']); |
|
| 552 | - $value = implode($value, $parts); |
|
| 553 | - } |
|
| 554 | - return $value; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Tell whether the field in the context really exists. |
|
| 559 | - * |
|
| 560 | - * @return bool |
|
| 561 | - */ |
|
| 562 | - protected function fieldExists() |
|
| 563 | - { |
|
| 564 | - if ($this->variables['hasField'] === null) { |
|
| 565 | - $dataType = $this->getDataType(); |
|
| 566 | - $fieldName = $this->getFieldName(); |
|
| 567 | - $this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName); |
|
| 568 | - } |
|
| 569 | - return $this->variables['hasField']; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @return string |
|
| 574 | - */ |
|
| 575 | - protected function getDataType() |
|
| 576 | - { |
|
| 577 | - return $this->variables['dataType']; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * @return string |
|
| 582 | - */ |
|
| 583 | - protected function getFieldName() |
|
| 584 | - { |
|
| 585 | - return $this->variables['fieldName']; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @return string |
|
| 590 | - */ |
|
| 591 | - protected function getFieldNameAndPath() |
|
| 592 | - { |
|
| 593 | - return $this->variables['fieldNameAndPath']; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @return Content |
|
| 598 | - */ |
|
| 599 | - protected function getObject() |
|
| 600 | - { |
|
| 601 | - return $this->variables['object']; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @return Content |
|
| 606 | - * @throws \InvalidArgumentException |
|
| 607 | - */ |
|
| 608 | - protected function getResolvedObject() |
|
| 609 | - { |
|
| 610 | - if (empty($this->variables['resolvedObject'])) { |
|
| 611 | - $object = $this->getObject(); |
|
| 612 | - $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 613 | - $this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath); |
|
| 614 | - } |
|
| 615 | - return $this->variables['resolvedObject']; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @return FieldPathResolver|object |
|
| 620 | - * @throws \InvalidArgumentException |
|
| 621 | - */ |
|
| 622 | - protected function getFieldPathResolver() |
|
| 623 | - { |
|
| 624 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @return ContentObjectResolver|object |
|
| 629 | - * @throws \InvalidArgumentException |
|
| 630 | - */ |
|
| 631 | - protected function getContentObjectResolver() |
|
| 632 | - { |
|
| 633 | - return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * @return \TYPO3\CMS\Core\Localization\LanguageService |
|
| 638 | - */ |
|
| 639 | - protected function getLabelService() |
|
| 640 | - { |
|
| 641 | - return $GLOBALS['LANG']; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * @return LanguageService|object |
|
| 646 | - * @throws \InvalidArgumentException |
|
| 647 | - */ |
|
| 648 | - protected function getLanguageService() |
|
| 649 | - { |
|
| 650 | - return GeneralUtility::makeInstance(LanguageService::class); |
|
| 651 | - } |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $columns = []; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Registry for storing variable values and speed up the processing. |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $variables = []; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param array $columns |
|
| 43 | + */ |
|
| 44 | + public function __construct(array $columns = []) |
|
| 45 | + { |
|
| 46 | + $this->columns = $columns; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Render a row to be displayed in the Grid given an Content Object. |
|
| 51 | + * |
|
| 52 | + * @param Content $object |
|
| 53 | + * @param int $rowIndex |
|
| 54 | + * @return array |
|
| 55 | + * @throws \Exception |
|
| 56 | + */ |
|
| 57 | + public function render(Content $object = null, $rowIndex = 0) |
|
| 58 | + { |
|
| 59 | + |
|
| 60 | + // Initialize returned array |
|
| 61 | + $output = []; |
|
| 62 | + |
|
| 63 | + foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) { |
|
| 64 | + |
|
| 65 | + $value = ''; // default is empty at first. |
|
| 66 | + |
|
| 67 | + $this->computeVariables($object, $fieldNameAndPath); |
|
| 68 | + |
|
| 69 | + // Only compute the value if it is going to be shown in the Grid. Lost of time otherwise! |
|
| 70 | + if (in_array($fieldNameAndPath, $this->columns)) { |
|
| 71 | + |
|
| 72 | + // Fetch value |
|
| 73 | + if (Tca::grid()->hasRenderers($fieldNameAndPath)) { |
|
| 74 | + |
|
| 75 | + $value = ''; |
|
| 76 | + $renderers = Tca::grid()->getRenderers($fieldNameAndPath); |
|
| 77 | + |
|
| 78 | + // if is relation has one |
|
| 79 | + foreach ($renderers as $rendererClassName => $rendererConfiguration) { |
|
| 80 | + |
|
| 81 | + /** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */ |
|
| 82 | + $rendererObject = GeneralUtility::makeInstance($rendererClassName); |
|
| 83 | + $value .= $rendererObject |
|
| 84 | + ->setObject($object) |
|
| 85 | + ->setFieldName($fieldNameAndPath) |
|
| 86 | + ->setRowIndex($rowIndex) |
|
| 87 | + ->setFieldConfiguration($configuration) |
|
| 88 | + ->setGridRendererConfiguration($rendererConfiguration) |
|
| 89 | + ->render(); |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + $value = $this->resolveValue($object, $fieldNameAndPath); |
|
| 93 | + $value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing. |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Possible formatting given by configuration. @see TCA['grid'] |
|
| 97 | + $value = $this->formatValue($value, $configuration); |
|
| 98 | + |
|
| 99 | + // Here, there is the chance to further "decorate" the value for inline editing, localization, ... |
|
| 100 | + if ($this->willBeEnriched()) { |
|
| 101 | + |
|
| 102 | + $localizedStructure = $this->initializeLocalizedStructure($value); |
|
| 103 | + |
|
| 104 | + if ($this->isEditable()) { |
|
| 105 | + $localizedStructure = $this->addEditableMarkup($localizedStructure); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($this->isLocalized()) { |
|
| 109 | + $localizedStructure = $this->addLocalizationMarkup($localizedStructure); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if ($this->hasIcon()) { |
|
| 113 | + $localizedStructure = $this->addSpriteIconMarkup($localizedStructure); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $value = $this->flattenStructure($localizedStructure); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Final wrap given by configuration. @see TCA['grid'] |
|
| 120 | + $value = $this->wrapValue($value, $configuration); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $output[$this->getFieldName()] = $value; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $output['DT_RowId'] = 'row-' . $object->getUid(); |
|
| 127 | + $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid()); |
|
| 128 | + |
|
| 129 | + return $output; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Flatten the localized structure to render the final value |
|
| 134 | + * |
|
| 135 | + * @param array $localizedStructure |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + protected function flattenStructure(array $localizedStructure) |
|
| 139 | + { |
|
| 140 | + |
|
| 141 | + // Flatten the structure. |
|
| 142 | + $value = ''; |
|
| 143 | + foreach ($localizedStructure as $structure) { |
|
| 144 | + $value .= sprintf('<div class="%s">%s</div>', |
|
| 145 | + $structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '', |
|
| 146 | + $structure['value'] |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + return $value; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Store some often used variable values and speed up the processing. |
|
| 154 | + * |
|
| 155 | + * @param Content $object |
|
| 156 | + * @param string $fieldNameAndPath |
|
| 157 | + * @return void |
|
| 158 | + */ |
|
| 159 | + protected function computeVariables(Content $object, $fieldNameAndPath) |
|
| 160 | + { |
|
| 161 | + $this->variables = []; |
|
| 162 | + $this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
| 163 | + $this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 164 | + $this->variables['fieldNameAndPath'] = $fieldNameAndPath; |
|
| 165 | + $this->variables['object'] = $object; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Tell whether the object will be decorated / wrapped such as |
|
| 170 | + * |
|
| 171 | + * @param string $value |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + protected function initializeLocalizedStructure($value) |
|
| 175 | + { |
|
| 176 | + |
|
| 177 | + $localizedStructure[] = [ |
|
| 178 | + 'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value, |
|
| 179 | + 'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED, |
|
| 180 | + 'language' => 0, |
|
| 181 | + 'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(), |
|
| 182 | + ]; |
|
| 183 | + |
|
| 184 | + if ($this->isLocalized()) { |
|
| 185 | + |
|
| 186 | + foreach ($this->getLanguageService()->getLanguages() as $language) { |
|
| 187 | + |
|
| 188 | + // Make sure the language is allowed for the current Backend User. |
|
| 189 | + if ($this->isLanguageAllowedForBackendUser($language)) { |
|
| 190 | + |
|
| 191 | + $resolvedObject = $this->getResolvedObject(); |
|
| 192 | + $fieldName = $this->getFieldName(); |
|
| 193 | + |
|
| 194 | + if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) { |
|
| 195 | + $localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName); |
|
| 196 | + $status = LocalizationStatus::LOCALIZED; |
|
| 197 | + |
|
| 198 | + // Replace blank value by something more meaningful for the End User. |
|
| 199 | + if (empty($localizedValue)) { |
|
| 200 | + $status = LocalizationStatus::EMPTY_VALUE; |
|
| 201 | + $localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : ''; |
|
| 202 | + } |
|
| 203 | + } else { |
|
| 204 | + $localizedValue = sprintf('<a href="%s" style="color: black">%s</a>', |
|
| 205 | + $this->getLocalizedUri($language['uid']), |
|
| 206 | + $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation') |
|
| 207 | + ); |
|
| 208 | + $status = LocalizationStatus::NOT_YET_LOCALIZED; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // Feed structure. |
|
| 212 | + $localizedStructure[] = [ |
|
| 213 | + 'value' => $localizedValue, |
|
| 214 | + 'status' => $status, |
|
| 215 | + 'language' => (int)$language['uid'], |
|
| 216 | + 'languageFlag' => $language['flag'], |
|
| 217 | + ]; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return $localizedStructure; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param array $language |
|
| 227 | + * @return bool |
|
| 228 | + */ |
|
| 229 | + protected function isLanguageAllowedForBackendUser(array $language) |
|
| 230 | + { |
|
| 231 | + return $this->getBackendUser()->checkLanguageAccess($language['uid']); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Returns a placeholder when the value is empty. |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + protected function getEmptyValuePlaceholder() |
|
| 240 | + { |
|
| 241 | + return sprintf('<i>%s</i>', |
|
| 242 | + $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing') |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose. |
|
| 248 | + * |
|
| 249 | + * @return bool |
|
| 250 | + */ |
|
| 251 | + protected function willBeEnriched() |
|
| 252 | + { |
|
| 253 | + |
|
| 254 | + $willBeEnriched = false; |
|
| 255 | + |
|
| 256 | + if ($this->fieldExists()) { |
|
| 257 | + $willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $willBeEnriched; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Tell whether the field in the context will be prepended by an icon. |
|
| 265 | + * |
|
| 266 | + * @return bool |
|
| 267 | + */ |
|
| 268 | + protected function hasIcon() |
|
| 269 | + { |
|
| 270 | + $dataType = $this->getDataType(); |
|
| 271 | + return Tca::table($dataType)->getLabelField() === $this->getFieldName(); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Tell whether the field in the context will be prepended by an icon. |
|
| 276 | + * |
|
| 277 | + * @return bool |
|
| 278 | + */ |
|
| 279 | + protected function isLocalized() |
|
| 280 | + { |
|
| 281 | + $object = $this->getObject(); |
|
| 282 | + $fieldName = $this->getFieldName(); |
|
| 283 | + $dataType = $this->getDataType(); |
|
| 284 | + $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 285 | + |
|
| 286 | + return $this->getLanguageService()->hasLanguages() |
|
| 287 | + && Tca::grid($object)->isLocalized($fieldNameAndPath) |
|
| 288 | + && Tca::table($dataType)->field($fieldName)->isLocalized(); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Add some markup to have the content editable in the Grid. |
|
| 293 | + * |
|
| 294 | + * @param array $localizedStructure |
|
| 295 | + * @return array |
|
| 296 | + */ |
|
| 297 | + protected function addEditableMarkup(array $localizedStructure) |
|
| 298 | + { |
|
| 299 | + |
|
| 300 | + $dataType = $this->getDataType(); |
|
| 301 | + $fieldName = $this->getFieldName(); |
|
| 302 | + |
|
| 303 | + foreach ($localizedStructure as $index => $structure) { |
|
| 304 | + if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) { |
|
| 305 | + $localizedStructure[$index]['value'] = sprintf('<span class="%s" data-language="%s">%s</span>', |
|
| 306 | + Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield', |
|
| 307 | + $structure['language'], |
|
| 308 | + $structure['value'] |
|
| 309 | + ); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + return $localizedStructure; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Add some markup related to the localization. |
|
| 317 | + * |
|
| 318 | + * @param array $localizedStructure |
|
| 319 | + * @return array |
|
| 320 | + */ |
|
| 321 | + protected function addLocalizationMarkup(array $localizedStructure) |
|
| 322 | + { |
|
| 323 | + |
|
| 324 | + foreach ($localizedStructure as $index => $structure) { |
|
| 325 | + |
|
| 326 | + $localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>', |
|
| 327 | + empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 328 | + $structure['value'] |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + return $localizedStructure; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Add some markup related to the prepended icon. |
|
| 336 | + * |
|
| 337 | + * @param array $localizedStructure |
|
| 338 | + * @return array |
|
| 339 | + */ |
|
| 340 | + protected function addSpriteIconMarkup(array $localizedStructure) |
|
| 341 | + { |
|
| 342 | + |
|
| 343 | + $object = $this->getObject(); |
|
| 344 | + |
|
| 345 | + foreach ($localizedStructure as $index => $structure) { |
|
| 346 | + |
|
| 347 | + $recordData = []; |
|
| 348 | + |
|
| 349 | + $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime'); |
|
| 350 | + foreach ($enablesMethods as $enableMethod) { |
|
| 351 | + |
|
| 352 | + $methodName = 'get' . $enableMethod . 'Field'; |
|
| 353 | + |
|
| 354 | + // Fetch possible hidden filed. |
|
| 355 | + $enableField = Tca::table($object)->$methodName(); |
|
| 356 | + if ($enableField) { |
|
| 357 | + $recordData[$enableField] = $object[$enableField]; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + // Get Enable Fields of the object to render the sprite with overlays. |
|
| 362 | + $localizedStructure[$index]['value'] = sprintf('%s %s', |
|
| 363 | + $this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL), |
|
| 364 | + $structure['value'] |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $localizedStructure; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Return whether the field given by the context is editable. |
|
| 373 | + * |
|
| 374 | + * @return boolean |
|
| 375 | + */ |
|
| 376 | + protected function isEditable() |
|
| 377 | + { |
|
| 378 | + $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 379 | + $dataType = $this->getDataType(); |
|
| 380 | + $fieldName = $this->getFieldName(); |
|
| 381 | + |
|
| 382 | + return Tca::grid()->isEditable($fieldNameAndPath) |
|
| 383 | + && Tca::table($dataType)->hasField($fieldName) |
|
| 384 | + && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only. |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Return the appropriate URI to create the translation. |
|
| 389 | + * |
|
| 390 | + * @param int $language |
|
| 391 | + * @return string |
|
| 392 | + */ |
|
| 393 | + protected function getLocalizedUri($language) |
|
| 394 | + { |
|
| 395 | + |
|
| 396 | + // Transmit recursive selection parameter. |
|
| 397 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
| 398 | + $parameters = GeneralUtility::_GP($parameterPrefix); |
|
| 399 | + |
|
| 400 | + $additionalParameters = array( |
|
| 401 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 402 | + 'controller' => 'Content', |
|
| 403 | + 'action' => 'localize', |
|
| 404 | + 'format' => 'json', |
|
| 405 | + 'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0, |
|
| 406 | + 'fieldNameAndPath' => $this->getFieldNameAndPath(), |
|
| 407 | + 'language' => $language, |
|
| 408 | + 'matches' => array( |
|
| 409 | + 'uid' => $this->getObject()->getUid(), |
|
| 410 | + ), |
|
| 411 | + ), |
|
| 412 | + ); |
|
| 413 | + |
|
| 414 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Compute the value for the Content object according to a field name. |
|
| 419 | + * |
|
| 420 | + * @param Content $object |
|
| 421 | + * @param string $fieldNameAndPath |
|
| 422 | + * @return string |
|
| 423 | + */ |
|
| 424 | + protected function resolveValue(Content $object, $fieldNameAndPath) |
|
| 425 | + { |
|
| 426 | + |
|
| 427 | + // Get the first part of the field name and |
|
| 428 | + $fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath); |
|
| 429 | + |
|
| 430 | + $value = $object[$fieldName]; |
|
| 431 | + |
|
| 432 | + // Relation but contains no data. |
|
| 433 | + if (is_array($value) && empty($value)) { |
|
| 434 | + $value = ''; |
|
| 435 | + } elseif ($value instanceof Content) { |
|
| 436 | + |
|
| 437 | + $fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 438 | + |
|
| 439 | + // true means the field name does not contains a path. "title" vs "metadata.title" |
|
| 440 | + // Fetch the default label |
|
| 441 | + if ($fieldNameOfForeignTable === $fieldName) { |
|
| 442 | + $foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable(); |
|
| 443 | + $fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField(); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + $value = $object[$fieldName][$fieldNameOfForeignTable]; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + return $value; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Check whether a string contains HTML tags. |
|
| 454 | + * |
|
| 455 | + * @param string $string the content to be analyzed |
|
| 456 | + * @return boolean |
|
| 457 | + */ |
|
| 458 | + protected function hasHtml($string) |
|
| 459 | + { |
|
| 460 | + $result = false; |
|
| 461 | + |
|
| 462 | + // We compare the length of the string with html tags and without html tags. |
|
| 463 | + if (strlen($string) !== strlen(strip_tags($string))) { |
|
| 464 | + $result = true; |
|
| 465 | + } |
|
| 466 | + return $result; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Check whether a string contains potential XSS. |
|
| 471 | + * |
|
| 472 | + * @param string $string the content to be analyzed |
|
| 473 | + * @return boolean |
|
| 474 | + */ |
|
| 475 | + protected function isClean($string) |
|
| 476 | + { |
|
| 477 | + |
|
| 478 | + // @todo implement me! |
|
| 479 | + $result = true; |
|
| 480 | + return $result; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Process the value |
|
| 485 | + * |
|
| 486 | + * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however! |
|
| 487 | + * e.g DefaultValueGridProcessor, TextAreaGridProcessor, ... |
|
| 488 | + * |
|
| 489 | + * @param string $value |
|
| 490 | + * @param Content $object |
|
| 491 | + * @param string $fieldNameAndPath |
|
| 492 | + * @return string |
|
| 493 | + * @throws InvalidKeyInArrayException |
|
| 494 | + */ |
|
| 495 | + protected function processValue($value, Content $object, $fieldNameAndPath) |
|
| 496 | + { |
|
| 497 | + |
|
| 498 | + // Set default value if $field name correspond to the label of the table |
|
| 499 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 500 | + if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) { |
|
| 501 | + $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title')); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + // Sanitize the value in case of "select" or "radio button". |
|
| 505 | + if (is_scalar($value)) { |
|
| 506 | + $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType(); |
|
| 507 | + if ($fieldType !== FieldType::TEXTAREA) { |
|
| 508 | + $value = htmlspecialchars($value); |
|
| 509 | + } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) { |
|
| 510 | + $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML. |
|
| 511 | + } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) { |
|
| 512 | + $value = nl2br($value); |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return $value; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Possible value formatting. |
|
| 521 | + * |
|
| 522 | + * @param string $value |
|
| 523 | + * @param array $configuration |
|
| 524 | + * @return string |
|
| 525 | + * @throws \InvalidArgumentException |
|
| 526 | + */ |
|
| 527 | + protected function formatValue($value, array $configuration) |
|
| 528 | + { |
|
| 529 | + if (empty($configuration['format'])) { |
|
| 530 | + return $value; |
|
| 531 | + } |
|
| 532 | + $className = $configuration['format']; |
|
| 533 | + |
|
| 534 | + /** @var FormatterInterface $formatter */ |
|
| 535 | + $formatter = GeneralUtility::makeInstance($className); |
|
| 536 | + $value = $formatter->format($value); |
|
| 537 | + |
|
| 538 | + return $value; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Possible value wrapping. |
|
| 543 | + * |
|
| 544 | + * @param string $value |
|
| 545 | + * @param array $configuration |
|
| 546 | + * @return string |
|
| 547 | + */ |
|
| 548 | + protected function wrapValue($value, array $configuration) |
|
| 549 | + { |
|
| 550 | + if (!empty($configuration['wrap'])) { |
|
| 551 | + $parts = explode('|', $configuration['wrap']); |
|
| 552 | + $value = implode($value, $parts); |
|
| 553 | + } |
|
| 554 | + return $value; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Tell whether the field in the context really exists. |
|
| 559 | + * |
|
| 560 | + * @return bool |
|
| 561 | + */ |
|
| 562 | + protected function fieldExists() |
|
| 563 | + { |
|
| 564 | + if ($this->variables['hasField'] === null) { |
|
| 565 | + $dataType = $this->getDataType(); |
|
| 566 | + $fieldName = $this->getFieldName(); |
|
| 567 | + $this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName); |
|
| 568 | + } |
|
| 569 | + return $this->variables['hasField']; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @return string |
|
| 574 | + */ |
|
| 575 | + protected function getDataType() |
|
| 576 | + { |
|
| 577 | + return $this->variables['dataType']; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * @return string |
|
| 582 | + */ |
|
| 583 | + protected function getFieldName() |
|
| 584 | + { |
|
| 585 | + return $this->variables['fieldName']; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @return string |
|
| 590 | + */ |
|
| 591 | + protected function getFieldNameAndPath() |
|
| 592 | + { |
|
| 593 | + return $this->variables['fieldNameAndPath']; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @return Content |
|
| 598 | + */ |
|
| 599 | + protected function getObject() |
|
| 600 | + { |
|
| 601 | + return $this->variables['object']; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @return Content |
|
| 606 | + * @throws \InvalidArgumentException |
|
| 607 | + */ |
|
| 608 | + protected function getResolvedObject() |
|
| 609 | + { |
|
| 610 | + if (empty($this->variables['resolvedObject'])) { |
|
| 611 | + $object = $this->getObject(); |
|
| 612 | + $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 613 | + $this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath); |
|
| 614 | + } |
|
| 615 | + return $this->variables['resolvedObject']; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @return FieldPathResolver|object |
|
| 620 | + * @throws \InvalidArgumentException |
|
| 621 | + */ |
|
| 622 | + protected function getFieldPathResolver() |
|
| 623 | + { |
|
| 624 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @return ContentObjectResolver|object |
|
| 629 | + * @throws \InvalidArgumentException |
|
| 630 | + */ |
|
| 631 | + protected function getContentObjectResolver() |
|
| 632 | + { |
|
| 633 | + return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * @return \TYPO3\CMS\Core\Localization\LanguageService |
|
| 638 | + */ |
|
| 639 | + protected function getLabelService() |
|
| 640 | + { |
|
| 641 | + return $GLOBALS['LANG']; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * @return LanguageService|object |
|
| 646 | + * @throws \InvalidArgumentException |
|
| 647 | + */ |
|
| 648 | + protected function getLanguageService() |
|
| 649 | + { |
|
| 650 | + return GeneralUtility::makeInstance(LanguageService::class); |
|
| 651 | + } |
|
| 652 | 652 | |
| 653 | 653 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | use Fab\Vidi\Tests\Functional\AbstractFunctionalTestCase; |
| 18 | 18 | |
| 19 | -require_once dirname(dirname(dirname(__FILE__))) . '/AbstractFunctionalTestCase.php'; |
|
| 19 | +require_once dirname(dirname(dirname(__FILE__))).'/AbstractFunctionalTestCase.php'; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Test case for class \Fab\Vidi\Domain\Model\Content. |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * @dataProvider propertyProvider |
| 114 | 114 | */ |
| 115 | 115 | public function testProperty($propertyName, $value) { |
| 116 | - $setter = 'set' . ucfirst($propertyName); |
|
| 117 | - $getter = 'get' . ucfirst($propertyName); |
|
| 116 | + $setter = 'set'.ucfirst($propertyName); |
|
| 117 | + $getter = 'get'.ucfirst($propertyName); |
|
| 118 | 118 | $this->markTestIncomplete(); # TCA must be faked |
| 119 | 119 | #call_user_func_array(array($this->fixture, $setter), array($value)); |
| 120 | 120 | #$this->assertEquals($value, call_user_func(array($this->fixture, $getter))); |
@@ -19,15 +19,15 @@ |
||
| 19 | 19 | class ButtonsSystem extends AbstractComponentView |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Rendering buttons in the grids given a Content object. |
|
| 24 | - * |
|
| 25 | - * @param Content $object |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function render(Content $object = null) |
|
| 29 | - { |
|
| 30 | - return ''; |
|
| 31 | - } |
|
| 22 | + /** |
|
| 23 | + * Rendering buttons in the grids given a Content object. |
|
| 24 | + * |
|
| 25 | + * @param Content $object |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function render(Content $object = null) |
|
| 29 | + { |
|
| 30 | + return ''; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -18,15 +18,15 @@ |
||
| 18 | 18 | class CheckboxSystem extends AbstractComponentView |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Returns a checkbox for the grids. |
|
| 23 | - * |
|
| 24 | - * @param Content $object |
|
| 25 | - * @param int $offset |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function render(Content $object = null, $offset = 0) |
|
| 29 | - { |
|
| 30 | - return ''; |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Returns a checkbox for the grids. |
|
| 23 | + * |
|
| 24 | + * @param Content $object |
|
| 25 | + * @param int $offset |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function render(Content $object = null, $offset = 0) |
|
| 29 | + { |
|
| 30 | + return ''; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -18,35 +18,35 @@ |
||
| 18 | 18 | class EditUri extends AbstractComponentView |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Renders a "edit" button to be placed in the grid. |
|
| 23 | - * |
|
| 24 | - * @param Content $object |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function render(Content $object = null) |
|
| 28 | - { |
|
| 29 | - $uri = BackendUtility::getModuleUrl( |
|
| 30 | - 'record_edit', |
|
| 31 | - array( |
|
| 32 | - $this->getEditParameterName($object) => 'edit', |
|
| 33 | - 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - return $uri; |
|
| 37 | - } |
|
| 21 | + /** |
|
| 22 | + * Renders a "edit" button to be placed in the grid. |
|
| 23 | + * |
|
| 24 | + * @param Content $object |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function render(Content $object = null) |
|
| 28 | + { |
|
| 29 | + $uri = BackendUtility::getModuleUrl( |
|
| 30 | + 'record_edit', |
|
| 31 | + array( |
|
| 32 | + $this->getEditParameterName($object) => 'edit', |
|
| 33 | + 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + return $uri; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Content $object |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - protected function getEditParameterName(Content $object) |
|
| 44 | - { |
|
| 45 | - return sprintf( |
|
| 46 | - 'edit[%s][%s]', |
|
| 47 | - $object->getDataType(), |
|
| 48 | - $object->getUid() |
|
| 49 | - ); |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Content $object |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + protected function getEditParameterName(Content $object) |
|
| 44 | + { |
|
| 45 | + return sprintf( |
|
| 46 | + 'edit[%s][%s]', |
|
| 47 | + $object->getDataType(), |
|
| 48 | + $object->getUid() |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | } |
@@ -17,102 +17,102 @@ |
||
| 17 | 17 | class Property |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - static protected $currentProperty; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - static protected $currentTable; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $storage = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param string $propertyName |
|
| 37 | - * @return $this |
|
| 38 | - * @throws \InvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - static public function name($propertyName) |
|
| 41 | - { |
|
| 42 | - self::$currentProperty = $propertyName; |
|
| 43 | - self::$currentTable = ''; // reset the table name value. |
|
| 44 | - return GeneralUtility::makeInstance(self::class); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string|Content $tableNameOrContentObject |
|
| 49 | - * @return $this |
|
| 50 | - */ |
|
| 51 | - public function of($tableNameOrContentObject) |
|
| 52 | - { |
|
| 53 | - // Resolve the table name. |
|
| 54 | - self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
| 55 | - $tableNameOrContentObject->getDataType() : |
|
| 56 | - $tableNameOrContentObject; |
|
| 57 | - return $this; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function toFieldName() |
|
| 64 | - { |
|
| 65 | - |
|
| 66 | - $propertyName = $this->getPropertyName(); |
|
| 67 | - $tableName = $this->getTableName(); |
|
| 68 | - |
|
| 69 | - if (empty($this->storage[$tableName][$propertyName])) { |
|
| 70 | - if ($this->storage[$tableName]) { |
|
| 71 | - $this->storage[$tableName] = []; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // Default case |
|
| 75 | - $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName); |
|
| 76 | - |
|
| 77 | - // Special case in case the field name does not follow the conventions "field_name" => "fieldName" |
|
| 78 | - // There is the chance to make some mapping |
|
| 79 | - if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'])) { |
|
| 80 | - $key = array_search($propertyName, $GLOBALS['TCA'][$tableName]['vidi']['mappings']); |
|
| 81 | - if ($key !== false) { |
|
| 82 | - $fieldName = $key; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->storage[$tableName][$propertyName] = $fieldName; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $this->storage[$tableName][$propertyName]; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - * @throws \RuntimeException |
|
| 95 | - */ |
|
| 96 | - protected function getPropertyName() |
|
| 97 | - { |
|
| 98 | - $propertyName = self::$currentProperty; |
|
| 99 | - if (empty($propertyName)) { |
|
| 100 | - throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
| 101 | - } |
|
| 102 | - return $propertyName; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - * @throws \RuntimeException |
|
| 108 | - */ |
|
| 109 | - protected function getTableName() |
|
| 110 | - { |
|
| 111 | - $tableName = self::$currentTable; |
|
| 112 | - if (empty($tableName)) { |
|
| 113 | - throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
| 114 | - } |
|
| 115 | - return $tableName; |
|
| 116 | - } |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + static protected $currentProperty; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + static protected $currentTable; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $storage = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param string $propertyName |
|
| 37 | + * @return $this |
|
| 38 | + * @throws \InvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + static public function name($propertyName) |
|
| 41 | + { |
|
| 42 | + self::$currentProperty = $propertyName; |
|
| 43 | + self::$currentTable = ''; // reset the table name value. |
|
| 44 | + return GeneralUtility::makeInstance(self::class); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string|Content $tableNameOrContentObject |
|
| 49 | + * @return $this |
|
| 50 | + */ |
|
| 51 | + public function of($tableNameOrContentObject) |
|
| 52 | + { |
|
| 53 | + // Resolve the table name. |
|
| 54 | + self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
| 55 | + $tableNameOrContentObject->getDataType() : |
|
| 56 | + $tableNameOrContentObject; |
|
| 57 | + return $this; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function toFieldName() |
|
| 64 | + { |
|
| 65 | + |
|
| 66 | + $propertyName = $this->getPropertyName(); |
|
| 67 | + $tableName = $this->getTableName(); |
|
| 68 | + |
|
| 69 | + if (empty($this->storage[$tableName][$propertyName])) { |
|
| 70 | + if ($this->storage[$tableName]) { |
|
| 71 | + $this->storage[$tableName] = []; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // Default case |
|
| 75 | + $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName); |
|
| 76 | + |
|
| 77 | + // Special case in case the field name does not follow the conventions "field_name" => "fieldName" |
|
| 78 | + // There is the chance to make some mapping |
|
| 79 | + if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'])) { |
|
| 80 | + $key = array_search($propertyName, $GLOBALS['TCA'][$tableName]['vidi']['mappings']); |
|
| 81 | + if ($key !== false) { |
|
| 82 | + $fieldName = $key; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->storage[$tableName][$propertyName] = $fieldName; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $this->storage[$tableName][$propertyName]; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + * @throws \RuntimeException |
|
| 95 | + */ |
|
| 96 | + protected function getPropertyName() |
|
| 97 | + { |
|
| 98 | + $propertyName = self::$currentProperty; |
|
| 99 | + if (empty($propertyName)) { |
|
| 100 | + throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
| 101 | + } |
|
| 102 | + return $propertyName; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + * @throws \RuntimeException |
|
| 108 | + */ |
|
| 109 | + protected function getTableName() |
|
| 110 | + { |
|
| 111 | + $tableName = self::$currentTable; |
|
| 112 | + if (empty($tableName)) { |
|
| 113 | + throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
| 114 | + } |
|
| 115 | + return $tableName; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | } |
@@ -58,8 +58,7 @@ |
||
| 58 | 58 | { |
| 59 | 59 | // Resolve the table name. |
| 60 | 60 | self::$currentTable = $tableNameOrContentObject instanceof Content ? |
| 61 | - $tableNameOrContentObject->getDataType() : |
|
| 62 | - $tableNameOrContentObject; |
|
| 61 | + $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
| 63 | 62 | return $this; |
| 64 | 63 | } |
| 65 | 64 | |
@@ -16,32 +16,32 @@ |
||
| 16 | 16 | class ResultSetStorage implements SingletonInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $resultSets = []; |
|
| 19 | + /** |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $resultSets = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $querySignature |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function get($querySignature) |
|
| 29 | - { |
|
| 30 | - $resultSet = null; |
|
| 31 | - if (isset($this->resultSets[$querySignature])) { |
|
| 32 | - $resultSet = $this->resultSets[$querySignature]; |
|
| 33 | - } |
|
| 34 | - return $resultSet; |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $querySignature |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function get($querySignature) |
|
| 29 | + { |
|
| 30 | + $resultSet = null; |
|
| 31 | + if (isset($this->resultSets[$querySignature])) { |
|
| 32 | + $resultSet = $this->resultSets[$querySignature]; |
|
| 33 | + } |
|
| 34 | + return $resultSet; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param $querySignature |
|
| 39 | - * @param array $resultSet |
|
| 40 | - * @internal param array $resultSets |
|
| 41 | - */ |
|
| 42 | - public function set($querySignature, array $resultSet) |
|
| 43 | - { |
|
| 44 | - $this->resultSets[$querySignature] = $resultSet; |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * @param $querySignature |
|
| 39 | + * @param array $resultSet |
|
| 40 | + * @internal param array $resultSets |
|
| 41 | + */ |
|
| 42 | + public function set($querySignature, array $resultSet) |
|
| 43 | + { |
|
| 44 | + $this->resultSets[$querySignature] = $resultSet; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | } |
@@ -14,45 +14,45 @@ |
||
| 14 | 14 | class Order |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The orderings |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $orderings = []; |
|
| 17 | + /** |
|
| 18 | + * The orderings |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $orderings = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Constructs a new Order |
|
| 26 | - * |
|
| 27 | - * @para array $orders |
|
| 28 | - * @param array $orders |
|
| 29 | - */ |
|
| 30 | - public function __construct($orders = array()) |
|
| 31 | - { |
|
| 32 | - foreach ($orders as $order => $direction) { |
|
| 33 | - $this->addOrdering($order, $direction); |
|
| 34 | - } |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * Constructs a new Order |
|
| 26 | + * |
|
| 27 | + * @para array $orders |
|
| 28 | + * @param array $orders |
|
| 29 | + */ |
|
| 30 | + public function __construct($orders = array()) |
|
| 31 | + { |
|
| 32 | + foreach ($orders as $order => $direction) { |
|
| 33 | + $this->addOrdering($order, $direction); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Add ordering |
|
| 39 | - * |
|
| 40 | - * @param string $order The order |
|
| 41 | - * @param string $direction ASC / DESC |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function addOrdering($order, $direction) |
|
| 45 | - { |
|
| 46 | - $this->orderings[$order] = $direction; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Add ordering |
|
| 39 | + * |
|
| 40 | + * @param string $order The order |
|
| 41 | + * @param string $direction ASC / DESC |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function addOrdering($order, $direction) |
|
| 45 | + { |
|
| 46 | + $this->orderings[$order] = $direction; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Returns the order |
|
| 51 | - * |
|
| 52 | - * @return array The order |
|
| 53 | - */ |
|
| 54 | - public function getOrderings() |
|
| 55 | - { |
|
| 56 | - return $this->orderings; |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * Returns the order |
|
| 51 | + * |
|
| 52 | + * @return array The order |
|
| 53 | + */ |
|
| 54 | + public function getOrderings() |
|
| 55 | + { |
|
| 56 | + return $this->orderings; |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -14,121 +14,121 @@ |
||
| 14 | 14 | class JsonResult |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var int |
|
| 19 | - */ |
|
| 20 | - protected $numberOfObjects = 0; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var int |
|
| 24 | - */ |
|
| 25 | - protected $numberOfProcessedObjects = 0; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $errorMessages = []; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - protected $processedObject = []; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $row = null; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return $this |
|
| 44 | - */ |
|
| 45 | - public function incrementNumberOfProcessedObjects() |
|
| 46 | - { |
|
| 47 | - $this->numberOfProcessedObjects++; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param string $errorMessages |
|
| 52 | - * @return $this |
|
| 53 | - */ |
|
| 54 | - public function addErrorMessages($errorMessages) |
|
| 55 | - { |
|
| 56 | - if (!empty($errorMessages)) { |
|
| 57 | - $this->errorMessages[] = $errorMessages; |
|
| 58 | - } else { |
|
| 59 | - $this->incrementNumberOfProcessedObjects(); |
|
| 60 | - } |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param array $errorMessages |
|
| 66 | - * @return $this |
|
| 67 | - */ |
|
| 68 | - public function setErrorMessages($errorMessages) |
|
| 69 | - { |
|
| 70 | - $this->errorMessages = $errorMessages; |
|
| 71 | - return $this; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param array $processedObject |
|
| 76 | - * @return $this |
|
| 77 | - */ |
|
| 78 | - public function setProcessedObject($processedObject) |
|
| 79 | - { |
|
| 80 | - $this->processedObject = $processedObject; |
|
| 81 | - return $this; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return $this |
|
| 86 | - */ |
|
| 87 | - public function hasErrors() |
|
| 88 | - { |
|
| 89 | - return !empty($this->errorMessages); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param mixed $numberOfObjects |
|
| 94 | - * @return $this |
|
| 95 | - */ |
|
| 96 | - public function setNumberOfObjects($numberOfObjects) |
|
| 97 | - { |
|
| 98 | - $this->numberOfObjects = $numberOfObjects; |
|
| 99 | - return $this; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param mixed $row |
|
| 104 | - * @return $this |
|
| 105 | - */ |
|
| 106 | - public function setRow(array $row) |
|
| 107 | - { |
|
| 108 | - $this->row = $row; |
|
| 109 | - return $this; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Convert $this to array |
|
| 114 | - * |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - public function toArray() |
|
| 118 | - { |
|
| 119 | - $arrayValues = array( |
|
| 120 | - 'numberOfObjects' => $this->numberOfObjects, |
|
| 121 | - 'numberOfProcessedObjects' => $this->numberOfProcessedObjects, |
|
| 122 | - 'hasErrors' => $this->hasErrors(), |
|
| 123 | - 'errorMessages' => $this->errorMessages, |
|
| 124 | - 'row' => $this->row, |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Only feed key processedObject if it has values. |
|
| 128 | - if (!empty($this->processedObject)) { |
|
| 129 | - $arrayValues['processedObject'] = $this->processedObject; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $arrayValues; |
|
| 133 | - } |
|
| 17 | + /** |
|
| 18 | + * @var int |
|
| 19 | + */ |
|
| 20 | + protected $numberOfObjects = 0; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var int |
|
| 24 | + */ |
|
| 25 | + protected $numberOfProcessedObjects = 0; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $errorMessages = []; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + protected $processedObject = []; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $row = null; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return $this |
|
| 44 | + */ |
|
| 45 | + public function incrementNumberOfProcessedObjects() |
|
| 46 | + { |
|
| 47 | + $this->numberOfProcessedObjects++; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $errorMessages |
|
| 52 | + * @return $this |
|
| 53 | + */ |
|
| 54 | + public function addErrorMessages($errorMessages) |
|
| 55 | + { |
|
| 56 | + if (!empty($errorMessages)) { |
|
| 57 | + $this->errorMessages[] = $errorMessages; |
|
| 58 | + } else { |
|
| 59 | + $this->incrementNumberOfProcessedObjects(); |
|
| 60 | + } |
|
| 61 | + return $this; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param array $errorMessages |
|
| 66 | + * @return $this |
|
| 67 | + */ |
|
| 68 | + public function setErrorMessages($errorMessages) |
|
| 69 | + { |
|
| 70 | + $this->errorMessages = $errorMessages; |
|
| 71 | + return $this; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param array $processedObject |
|
| 76 | + * @return $this |
|
| 77 | + */ |
|
| 78 | + public function setProcessedObject($processedObject) |
|
| 79 | + { |
|
| 80 | + $this->processedObject = $processedObject; |
|
| 81 | + return $this; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return $this |
|
| 86 | + */ |
|
| 87 | + public function hasErrors() |
|
| 88 | + { |
|
| 89 | + return !empty($this->errorMessages); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param mixed $numberOfObjects |
|
| 94 | + * @return $this |
|
| 95 | + */ |
|
| 96 | + public function setNumberOfObjects($numberOfObjects) |
|
| 97 | + { |
|
| 98 | + $this->numberOfObjects = $numberOfObjects; |
|
| 99 | + return $this; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param mixed $row |
|
| 104 | + * @return $this |
|
| 105 | + */ |
|
| 106 | + public function setRow(array $row) |
|
| 107 | + { |
|
| 108 | + $this->row = $row; |
|
| 109 | + return $this; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Convert $this to array |
|
| 114 | + * |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + public function toArray() |
|
| 118 | + { |
|
| 119 | + $arrayValues = array( |
|
| 120 | + 'numberOfObjects' => $this->numberOfObjects, |
|
| 121 | + 'numberOfProcessedObjects' => $this->numberOfProcessedObjects, |
|
| 122 | + 'hasErrors' => $this->hasErrors(), |
|
| 123 | + 'errorMessages' => $this->errorMessages, |
|
| 124 | + 'row' => $this->row, |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Only feed key processedObject if it has values. |
|
| 128 | + if (!empty($this->processedObject)) { |
|
| 129 | + $arrayValues['processedObject'] = $this->processedObject; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $arrayValues; |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | \ No newline at end of file |