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