@@ -18,29 +18,29 @@ |
||
| 18 | 18 | class VidiModulesAspect implements TableConfigurationPostProcessingHookInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Initialize and populate TBE_MODULES_EXT with default data. |
|
| 23 | - * |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - public function processData() |
|
| 27 | - { |
|
| 28 | - |
|
| 29 | - /** @var ModuleLoader $moduleLoader */ |
|
| 30 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - $configuration = GeneralUtility::makeInstance( |
|
| 34 | - ExtensionConfiguration::class |
|
| 35 | - )->get('vidi'); |
|
| 36 | - |
|
| 37 | - foreach (GeneralUtility::trimExplode(',', $configuration['data_types'],true) as $dataType) { |
|
| 38 | - if (!$moduleLoader->isRegistered($dataType)) { |
|
| 39 | - $moduleLoader->setDataType($dataType) |
|
| 40 | - #->isShown(false) |
|
| 41 | - ->register(); |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - } |
|
| 21 | + /** |
|
| 22 | + * Initialize and populate TBE_MODULES_EXT with default data. |
|
| 23 | + * |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + public function processData() |
|
| 27 | + { |
|
| 28 | + |
|
| 29 | + /** @var ModuleLoader $moduleLoader */ |
|
| 30 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + $configuration = GeneralUtility::makeInstance( |
|
| 34 | + ExtensionConfiguration::class |
|
| 35 | + )->get('vidi'); |
|
| 36 | + |
|
| 37 | + foreach (GeneralUtility::trimExplode(',', $configuration['data_types'],true) as $dataType) { |
|
| 38 | + if (!$moduleLoader->isRegistered($dataType)) { |
|
| 39 | + $moduleLoader->setDataType($dataType) |
|
| 40 | + #->isShown(false) |
|
| 41 | + ->register(); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | ExtensionConfiguration::class |
| 35 | 35 | )->get('vidi'); |
| 36 | 36 | |
| 37 | - foreach (GeneralUtility::trimExplode(',', $configuration['data_types'],true) as $dataType) { |
|
| 37 | + foreach (GeneralUtility::trimExplode(',', $configuration['data_types'], true) as $dataType) { |
|
| 38 | 38 | if (!$moduleLoader->isRegistered($dataType)) { |
| 39 | 39 | $moduleLoader->setDataType($dataType) |
| 40 | 40 | #->isShown(false) |
@@ -21,168 +21,168 @@ |
||
| 21 | 21 | class LanguageService implements SingletonInterface |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $languages; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $defaultIcon; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Store the localized records to boost up performance. |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $localizedRecordStorage; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Returns available language records. |
|
| 43 | - * The method stores the records in the property to speed up the process as the method can be often called. |
|
| 44 | - * |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function getLanguages() |
|
| 48 | - { |
|
| 49 | - if ($this->languages === null) { |
|
| 50 | - $this->languages = $this->getDataService()->getRecords('sys_language'); |
|
| 51 | - } |
|
| 52 | - return $this->languages; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Returns a localized record according to a Content object and a language identifier. |
|
| 57 | - * Notice! This method does not overlay anything but simply returns the raw localized record. |
|
| 58 | - * |
|
| 59 | - * @param Content $object |
|
| 60 | - * @param int $language |
|
| 61 | - * @return Content |
|
| 62 | - */ |
|
| 63 | - public function getLocalizedContent(Content $object, $language) |
|
| 64 | - { |
|
| 65 | - |
|
| 66 | - // We want to cache data per Content object. Retrieve the Object hash. |
|
| 67 | - $objectHash = spl_object_hash($object); |
|
| 68 | - |
|
| 69 | - // Initialize the storage |
|
| 70 | - if (empty($this->localizedRecordStorage[$objectHash])) { |
|
| 71 | - $this->localizedRecordStorage[$objectHash] = []; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if (empty($this->localizedRecordStorage[$objectHash][$language])) { |
|
| 75 | - |
|
| 76 | - $localizedRecord = $this->getDataService()->getRecord( |
|
| 77 | - $object->getDataType(), |
|
| 78 | - [ |
|
| 79 | - Tca::table($object)->getLanguageParentField() => $object->getUid(), // e.g. l10n_parent |
|
| 80 | - Tca::table($object)->getLanguageField() => $language, // e.g. sys_language_uid |
|
| 81 | - ] |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - if ($localizedRecord) { |
|
| 85 | - $localizedContent = GeneralUtility::makeInstance(Content::class, $object->getDataType(), $localizedRecord); |
|
| 86 | - $this->localizedRecordStorage[$objectHash][$language] = $localizedContent; |
|
| 87 | - } else { |
|
| 88 | - $this->localizedRecordStorage[$objectHash][$language] = []; // We want an array at least, even if empty. |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $this->localizedRecordStorage[$objectHash][$language]; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Tell whether the given Content object has a localization. |
|
| 97 | - * |
|
| 98 | - * @param Content $object |
|
| 99 | - * @param int $language |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function hasLocalization(Content $object, $language) |
|
| 103 | - { |
|
| 104 | - $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 105 | - return !empty($localizedRecord); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Returns a localized field according to a Content object and a language identifier. |
|
| 110 | - * Notice! If there is not translation, simply returns an empty string. |
|
| 111 | - * |
|
| 112 | - * @param Content $object |
|
| 113 | - * @param int $language |
|
| 114 | - * @param string $fieldName |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function getLocalizedFieldName(Content $object, $language, $fieldName) |
|
| 118 | - { |
|
| 119 | - $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 120 | - return empty($localizedRecord) ? '' : $localizedRecord[$fieldName]; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Returns the default language configured by TSConfig. |
|
| 125 | - * |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function getDefaultFlag() |
|
| 129 | - { |
|
| 130 | - |
|
| 131 | - if ($this->defaultIcon === null) { |
|
| 132 | - |
|
| 133 | - $defaultFlag = ''; // default value |
|
| 134 | - |
|
| 135 | - $tsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig(0, 'mod.SHARED'); |
|
| 136 | - |
|
| 137 | - // Fallback non sprite-configuration |
|
| 138 | - if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== false) { |
|
| 139 | - $defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $this->defaultIcon = $defaultFlag; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $this->defaultIcon; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Returns whether the system includes language records. |
|
| 150 | - * |
|
| 151 | - * @return bool |
|
| 152 | - */ |
|
| 153 | - public function hasLanguages() |
|
| 154 | - { |
|
| 155 | - $languages = $this->getLanguages(); |
|
| 156 | - return !empty($languages); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Tell whether the given language exists. |
|
| 161 | - * |
|
| 162 | - * @param int $language |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - public function languageExists($language) |
|
| 166 | - { |
|
| 167 | - $languages = $this->getLanguages(); |
|
| 168 | - |
|
| 169 | - $LanguageExists = false; |
|
| 170 | - foreach ($languages as $_language) { |
|
| 171 | - if ((int)$_language['uid'] === (int)$language) { |
|
| 172 | - $LanguageExists = true; |
|
| 173 | - break; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $LanguageExists; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @return object|DataService |
|
| 182 | - */ |
|
| 183 | - protected function getDataService(): DataService |
|
| 184 | - { |
|
| 185 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 186 | - } |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $languages; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $defaultIcon; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Store the localized records to boost up performance. |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $localizedRecordStorage; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Returns available language records. |
|
| 43 | + * The method stores the records in the property to speed up the process as the method can be often called. |
|
| 44 | + * |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function getLanguages() |
|
| 48 | + { |
|
| 49 | + if ($this->languages === null) { |
|
| 50 | + $this->languages = $this->getDataService()->getRecords('sys_language'); |
|
| 51 | + } |
|
| 52 | + return $this->languages; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Returns a localized record according to a Content object and a language identifier. |
|
| 57 | + * Notice! This method does not overlay anything but simply returns the raw localized record. |
|
| 58 | + * |
|
| 59 | + * @param Content $object |
|
| 60 | + * @param int $language |
|
| 61 | + * @return Content |
|
| 62 | + */ |
|
| 63 | + public function getLocalizedContent(Content $object, $language) |
|
| 64 | + { |
|
| 65 | + |
|
| 66 | + // We want to cache data per Content object. Retrieve the Object hash. |
|
| 67 | + $objectHash = spl_object_hash($object); |
|
| 68 | + |
|
| 69 | + // Initialize the storage |
|
| 70 | + if (empty($this->localizedRecordStorage[$objectHash])) { |
|
| 71 | + $this->localizedRecordStorage[$objectHash] = []; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if (empty($this->localizedRecordStorage[$objectHash][$language])) { |
|
| 75 | + |
|
| 76 | + $localizedRecord = $this->getDataService()->getRecord( |
|
| 77 | + $object->getDataType(), |
|
| 78 | + [ |
|
| 79 | + Tca::table($object)->getLanguageParentField() => $object->getUid(), // e.g. l10n_parent |
|
| 80 | + Tca::table($object)->getLanguageField() => $language, // e.g. sys_language_uid |
|
| 81 | + ] |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + if ($localizedRecord) { |
|
| 85 | + $localizedContent = GeneralUtility::makeInstance(Content::class, $object->getDataType(), $localizedRecord); |
|
| 86 | + $this->localizedRecordStorage[$objectHash][$language] = $localizedContent; |
|
| 87 | + } else { |
|
| 88 | + $this->localizedRecordStorage[$objectHash][$language] = []; // We want an array at least, even if empty. |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $this->localizedRecordStorage[$objectHash][$language]; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Tell whether the given Content object has a localization. |
|
| 97 | + * |
|
| 98 | + * @param Content $object |
|
| 99 | + * @param int $language |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function hasLocalization(Content $object, $language) |
|
| 103 | + { |
|
| 104 | + $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 105 | + return !empty($localizedRecord); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Returns a localized field according to a Content object and a language identifier. |
|
| 110 | + * Notice! If there is not translation, simply returns an empty string. |
|
| 111 | + * |
|
| 112 | + * @param Content $object |
|
| 113 | + * @param int $language |
|
| 114 | + * @param string $fieldName |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function getLocalizedFieldName(Content $object, $language, $fieldName) |
|
| 118 | + { |
|
| 119 | + $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 120 | + return empty($localizedRecord) ? '' : $localizedRecord[$fieldName]; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Returns the default language configured by TSConfig. |
|
| 125 | + * |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function getDefaultFlag() |
|
| 129 | + { |
|
| 130 | + |
|
| 131 | + if ($this->defaultIcon === null) { |
|
| 132 | + |
|
| 133 | + $defaultFlag = ''; // default value |
|
| 134 | + |
|
| 135 | + $tsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig(0, 'mod.SHARED'); |
|
| 136 | + |
|
| 137 | + // Fallback non sprite-configuration |
|
| 138 | + if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== false) { |
|
| 139 | + $defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $this->defaultIcon = $defaultFlag; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $this->defaultIcon; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Returns whether the system includes language records. |
|
| 150 | + * |
|
| 151 | + * @return bool |
|
| 152 | + */ |
|
| 153 | + public function hasLanguages() |
|
| 154 | + { |
|
| 155 | + $languages = $this->getLanguages(); |
|
| 156 | + return !empty($languages); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Tell whether the given language exists. |
|
| 161 | + * |
|
| 162 | + * @param int $language |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + public function languageExists($language) |
|
| 166 | + { |
|
| 167 | + $languages = $this->getLanguages(); |
|
| 168 | + |
|
| 169 | + $LanguageExists = false; |
|
| 170 | + foreach ($languages as $_language) { |
|
| 171 | + if ((int)$_language['uid'] === (int)$language) { |
|
| 172 | + $LanguageExists = true; |
|
| 173 | + break; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $LanguageExists; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @return object|DataService |
|
| 182 | + */ |
|
| 183 | + protected function getDataService(): DataService |
|
| 184 | + { |
|
| 185 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | } |
@@ -19,47 +19,47 @@ |
||
| 19 | 19 | class DeleteButton extends AbstractComponentView |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Renders a "delete" button to be placed in the grid. |
|
| 24 | - * |
|
| 25 | - * @param Content $object |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function render(Content $object = null) |
|
| 29 | - { |
|
| 30 | - $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
| 31 | - $label = $object[$labelField] ? $object[$labelField] : $object->getUid(); |
|
| 22 | + /** |
|
| 23 | + * Renders a "delete" button to be placed in the grid. |
|
| 24 | + * |
|
| 25 | + * @param Content $object |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function render(Content $object = null) |
|
| 29 | + { |
|
| 30 | + $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
| 31 | + $label = $object[$labelField] ? $object[$labelField] : $object->getUid(); |
|
| 32 | 32 | |
| 33 | - return $this->makeLinkButton() |
|
| 34 | - ->setHref($this->getDeleteUri($object)) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - 'label' => $label, |
|
| 39 | - ]) |
|
| 40 | - ->setClasses('btn-delete') |
|
| 41 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:delete')) |
|
| 42 | - ->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL)) |
|
| 43 | - ->render(); |
|
| 44 | - } |
|
| 33 | + return $this->makeLinkButton() |
|
| 34 | + ->setHref($this->getDeleteUri($object)) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + 'label' => $label, |
|
| 39 | + ]) |
|
| 40 | + ->setClasses('btn-delete') |
|
| 41 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:delete')) |
|
| 42 | + ->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL)) |
|
| 43 | + ->render(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param Content $object |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - protected function getDeleteUri(Content $object) |
|
| 51 | - { |
|
| 52 | - $additionalParameters = array( |
|
| 53 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 54 | - 'controller' => 'Content', |
|
| 55 | - 'action' => 'delete', |
|
| 56 | - 'format' => 'json', |
|
| 57 | - 'matches' => array( |
|
| 58 | - 'uid' => $object->getUid(), |
|
| 59 | - ), |
|
| 60 | - ), |
|
| 61 | - ); |
|
| 62 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 63 | - } |
|
| 46 | + /** |
|
| 47 | + * @param Content $object |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + protected function getDeleteUri(Content $object) |
|
| 51 | + { |
|
| 52 | + $additionalParameters = array( |
|
| 53 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 54 | + 'controller' => 'Content', |
|
| 55 | + 'action' => 'delete', |
|
| 56 | + 'format' => 'json', |
|
| 57 | + 'matches' => array( |
|
| 58 | + 'uid' => $object->getUid(), |
|
| 59 | + ), |
|
| 60 | + ), |
|
| 61 | + ); |
|
| 62 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
@@ -18,52 +18,52 @@ |
||
| 18 | 18 | class ClipboardButton extends AbstractComponentView |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Renders a "clipboard" button to be placed in the doc header. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - $button = $this->makeLinkButton() |
|
| 29 | - ->setHref($this->getShowClipboardUri()) |
|
| 30 | - ->setDataAttributes([ |
|
| 31 | - 'style' => $this->getClipboardService()->hasItems() ? '' : 'display: none;', |
|
| 32 | - ]) |
|
| 33 | - ->setClasses('btn-clipboard-copy-or-move') |
|
| 34 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:clipboard.copy_or_move')) |
|
| 35 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)) |
|
| 36 | - ->render(); |
|
| 21 | + /** |
|
| 22 | + * Renders a "clipboard" button to be placed in the doc header. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + $button = $this->makeLinkButton() |
|
| 29 | + ->setHref($this->getShowClipboardUri()) |
|
| 30 | + ->setDataAttributes([ |
|
| 31 | + 'style' => $this->getClipboardService()->hasItems() ? '' : 'display: none;', |
|
| 32 | + ]) |
|
| 33 | + ->setClasses('btn-clipboard-copy-or-move') |
|
| 34 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:clipboard.copy_or_move')) |
|
| 35 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)) |
|
| 36 | + ->render(); |
|
| 37 | 37 | |
| 38 | - // Hack! No API for adding a style upon a button |
|
| 39 | - $button = str_replace('data-style', 'style', $button); |
|
| 38 | + // Hack! No API for adding a style upon a button |
|
| 39 | + $button = str_replace('data-style', 'style', $button); |
|
| 40 | 40 | |
| 41 | - $output = sprintf('<div style="float: left; margin-right: 3px">%s</div>', $button); |
|
| 42 | - return $output; |
|
| 43 | - } |
|
| 41 | + $output = sprintf('<div style="float: left; margin-right: 3px">%s</div>', $button); |
|
| 42 | + return $output; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - protected function getShowClipboardUri() |
|
| 49 | - { |
|
| 50 | - $additionalParameters = array( |
|
| 51 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 52 | - 'controller' => 'Clipboard', |
|
| 53 | - 'action' => 'show', |
|
| 54 | - ), |
|
| 55 | - ); |
|
| 56 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 57 | - } |
|
| 45 | + /** |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + protected function getShowClipboardUri() |
|
| 49 | + { |
|
| 50 | + $additionalParameters = array( |
|
| 51 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 52 | + 'controller' => 'Clipboard', |
|
| 53 | + 'action' => 'show', |
|
| 54 | + ), |
|
| 55 | + ); |
|
| 56 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the Vidi Module Loader. |
|
| 61 | - * |
|
| 62 | - * @return ClipboardService|object |
|
| 63 | - */ |
|
| 64 | - protected function getClipboardService() |
|
| 65 | - { |
|
| 66 | - return GeneralUtility::makeInstance(ClipboardService::class); |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Get the Vidi Module Loader. |
|
| 61 | + * |
|
| 62 | + * @return ClipboardService|object |
|
| 63 | + */ |
|
| 64 | + protected function getClipboardService() |
|
| 65 | + { |
|
| 66 | + return GeneralUtility::makeInstance(ClipboardService::class); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | } |
@@ -20,35 +20,35 @@ |
||
| 20 | 20 | class EditButton extends AbstractComponentView |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Renders a "edit" button to be placed in the grid. |
|
| 25 | - * |
|
| 26 | - * @param Content $object |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function render(Content $object = null) |
|
| 30 | - { |
|
| 31 | - $editUri = $this->getUriRenderer()->render($object); |
|
| 23 | + /** |
|
| 24 | + * Renders a "edit" button to be placed in the grid. |
|
| 25 | + * |
|
| 26 | + * @param Content $object |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function render(Content $object = null) |
|
| 30 | + { |
|
| 31 | + $editUri = $this->getUriRenderer()->render($object); |
|
| 32 | 32 | |
| 33 | - return $this->makeLinkButton() |
|
| 34 | - ->setHref($editUri) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - ]) |
|
| 39 | - ->setClasses('btn-edit') |
|
| 40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:edit')) |
|
| 41 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
| 42 | - ->render(); |
|
| 43 | - } |
|
| 33 | + return $this->makeLinkButton() |
|
| 34 | + ->setHref($editUri) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + ]) |
|
| 39 | + ->setClasses('btn-edit') |
|
| 40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:edit')) |
|
| 41 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
| 42 | + ->render(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return EditUri |
|
| 47 | - * @throws \InvalidArgumentException |
|
| 48 | - */ |
|
| 49 | - protected function getUriRenderer() |
|
| 50 | - { |
|
| 51 | - return GeneralUtility::makeInstance(EditUri::class); |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * @return EditUri |
|
| 47 | + * @throws \InvalidArgumentException |
|
| 48 | + */ |
|
| 49 | + protected function getUriRenderer() |
|
| 50 | + { |
|
| 51 | + return GeneralUtility::makeInstance(EditUri::class); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
@@ -22,109 +22,109 @@ |
||
| 22 | 22 | class NewButton extends AbstractComponentView |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Renders a "new" button to be placed in the doc header. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function render(): string |
|
| 31 | - { |
|
| 32 | - $output = ''; |
|
| 25 | + /** |
|
| 26 | + * Renders a "new" button to be placed in the doc header. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function render(): string |
|
| 31 | + { |
|
| 32 | + $output = ''; |
|
| 33 | 33 | |
| 34 | - // New button only for the current data type. |
|
| 35 | - if ($this->getModulePidService()->isConfiguredPidValid()) { |
|
| 36 | - $output = $this->makeLinkButton()->setHref($this->getNewUri()) |
|
| 37 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:newRecordGeneral')) |
|
| 38 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)) |
|
| 39 | - ->render(); |
|
| 40 | - } |
|
| 41 | - return $output; |
|
| 42 | - } |
|
| 34 | + // New button only for the current data type. |
|
| 35 | + if ($this->getModulePidService()->isConfiguredPidValid()) { |
|
| 36 | + $output = $this->makeLinkButton()->setHref($this->getNewUri()) |
|
| 37 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:newRecordGeneral')) |
|
| 38 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)) |
|
| 39 | + ->render(); |
|
| 40 | + } |
|
| 41 | + return $output; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Render a create URI given a data type. |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - protected function getUriWizardNew(): string |
|
| 50 | - { |
|
| 51 | - // Return URL in any case. |
|
| 52 | - $arguments['returnUrl'] = $this->getModuleLoader()->getModuleUrl(); |
|
| 44 | + /** |
|
| 45 | + * Render a create URI given a data type. |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + protected function getUriWizardNew(): string |
|
| 50 | + { |
|
| 51 | + // Return URL in any case. |
|
| 52 | + $arguments['returnUrl'] = $this->getModuleLoader()->getModuleUrl(); |
|
| 53 | 53 | |
| 54 | - // Add possible id parameter |
|
| 55 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 56 | - $arguments['id'] = GeneralUtility::_GP(Parameter::PID); |
|
| 57 | - } |
|
| 54 | + // Add possible id parameter |
|
| 55 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 56 | + $arguments['id'] = GeneralUtility::_GP(Parameter::PID); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $uri = BackendUtility::getModuleUrl( |
|
| 60 | - 'db_new', |
|
| 61 | - $arguments |
|
| 62 | - ); |
|
| 59 | + $uri = BackendUtility::getModuleUrl( |
|
| 60 | + 'db_new', |
|
| 61 | + $arguments |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - return $uri; |
|
| 65 | - } |
|
| 64 | + return $uri; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Render a create URI given a data type. |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - protected function getNewUri(): string |
|
| 73 | - { |
|
| 74 | - $uri = BackendUtility::getModuleUrl( |
|
| 75 | - 'record_edit', |
|
| 76 | - array( |
|
| 77 | - $this->getNewParameterName() => 'new', |
|
| 78 | - 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 79 | - ) |
|
| 80 | - ); |
|
| 81 | - return $uri; |
|
| 82 | - } |
|
| 67 | + /** |
|
| 68 | + * Render a create URI given a data type. |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + protected function getNewUri(): string |
|
| 73 | + { |
|
| 74 | + $uri = BackendUtility::getModuleUrl( |
|
| 75 | + 'record_edit', |
|
| 76 | + array( |
|
| 77 | + $this->getNewParameterName() => 'new', |
|
| 78 | + 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 79 | + ) |
|
| 80 | + ); |
|
| 81 | + return $uri; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - protected function getNewParameterName(): string |
|
| 88 | - { |
|
| 89 | - return sprintf( |
|
| 90 | - 'edit[%s][%s]', |
|
| 91 | - $this->getModuleLoader()->getDataType(), |
|
| 92 | - $this->getStoragePid() |
|
| 93 | - ); |
|
| 94 | - } |
|
| 84 | + /** |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + protected function getNewParameterName(): string |
|
| 88 | + { |
|
| 89 | + return sprintf( |
|
| 90 | + 'edit[%s][%s]', |
|
| 91 | + $this->getModuleLoader()->getDataType(), |
|
| 92 | + $this->getStoragePid() |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Return the default configured pid. |
|
| 98 | - * |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - protected function getStoragePid(): int |
|
| 102 | - { |
|
| 103 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 104 | - $pid = GeneralUtility::_GP(Parameter::PID); |
|
| 105 | - } elseif ((int)Tca::table()->get('rootLevel') === 1) { |
|
| 106 | - $pid = 0; |
|
| 107 | - } else { |
|
| 108 | - // Get configuration from User TSConfig if any |
|
| 109 | - $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->getModuleLoader()->getDataType()); |
|
| 110 | - $tsConfig = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
| 111 | - $pid = $tsConfig['value']; |
|
| 96 | + /** |
|
| 97 | + * Return the default configured pid. |
|
| 98 | + * |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + protected function getStoragePid(): int |
|
| 102 | + { |
|
| 103 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 104 | + $pid = GeneralUtility::_GP(Parameter::PID); |
|
| 105 | + } elseif ((int)Tca::table()->get('rootLevel') === 1) { |
|
| 106 | + $pid = 0; |
|
| 107 | + } else { |
|
| 108 | + // Get configuration from User TSConfig if any |
|
| 109 | + $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->getModuleLoader()->getDataType()); |
|
| 110 | + $tsConfig = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
| 111 | + $pid = $tsConfig['value']; |
|
| 112 | 112 | |
| 113 | - // Get pid from Module Loader |
|
| 114 | - if (null === $pid) { |
|
| 115 | - $pid = $this->getModuleLoader()->getDefaultPid(); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - return (int)$pid; |
|
| 119 | - } |
|
| 113 | + // Get pid from Module Loader |
|
| 114 | + if (null === $pid) { |
|
| 115 | + $pid = $this->getModuleLoader()->getDefaultPid(); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + return (int)$pid; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @return ModulePidService|object |
|
| 123 | - */ |
|
| 124 | - public function getModulePidService() |
|
| 125 | - { |
|
| 126 | - /** @var ModulePidService $modulePidService */ |
|
| 127 | - return GeneralUtility::makeInstance(ModulePidService::class); |
|
| 128 | - } |
|
| 121 | + /** |
|
| 122 | + * @return ModulePidService|object |
|
| 123 | + */ |
|
| 124 | + public function getModulePidService() |
|
| 125 | + { |
|
| 126 | + /** @var ModulePidService $modulePidService */ |
|
| 127 | + return GeneralUtility::makeInstance(ModulePidService::class); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
@@ -17,17 +17,17 @@ |
||
| 17 | 17 | class MassEditMenuItem extends AbstractComponentView |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Renders a "mass edit" menu item to be placed in the grid menu. |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - * @throws \InvalidArgumentException |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - return sprintf('<li><a href="#" class="dropdown-item mass-edit">%s %s (not implemented)</a></li>', |
|
| 29 | - $this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL), |
|
| 30 | - $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:edit') |
|
| 31 | - ); |
|
| 32 | - } |
|
| 20 | + /** |
|
| 21 | + * Renders a "mass edit" menu item to be placed in the grid menu. |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + * @throws \InvalidArgumentException |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + return sprintf('<li><a href="#" class="dropdown-item mass-edit">%s %s (not implemented)</a></li>', |
|
| 29 | + $this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL), |
|
| 30 | + $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:edit') |
|
| 31 | + ); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -20,48 +20,48 @@ |
||
| 20 | 20 | abstract class AbstractComponentView implements ViewComponentInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get the Vidi Module Loader. |
|
| 25 | - * |
|
| 26 | - * @return ModuleLoader|object |
|
| 27 | - */ |
|
| 28 | - protected function getModuleLoader() |
|
| 29 | - { |
|
| 30 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 31 | - } |
|
| 23 | + /** |
|
| 24 | + * Get the Vidi Module Loader. |
|
| 25 | + * |
|
| 26 | + * @return ModuleLoader|object |
|
| 27 | + */ |
|
| 28 | + protected function getModuleLoader() |
|
| 29 | + { |
|
| 30 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Returns an instance of the current Backend User. |
|
| 35 | - * |
|
| 36 | - * @return BackendUserAuthentication |
|
| 37 | - */ |
|
| 38 | - protected function getBackendUser() |
|
| 39 | - { |
|
| 40 | - return $GLOBALS['BE_USER']; |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Returns an instance of the current Backend User. |
|
| 35 | + * |
|
| 36 | + * @return BackendUserAuthentication |
|
| 37 | + */ |
|
| 38 | + protected function getBackendUser() |
|
| 39 | + { |
|
| 40 | + return $GLOBALS['BE_USER']; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return LanguageService|object |
|
| 45 | - */ |
|
| 46 | - protected function getLanguageService() |
|
| 47 | - { |
|
| 48 | - return GeneralUtility::makeInstance(LanguageService::class); |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * @return LanguageService|object |
|
| 45 | + */ |
|
| 46 | + protected function getLanguageService() |
|
| 47 | + { |
|
| 48 | + return GeneralUtility::makeInstance(LanguageService::class); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return IconFactory|object |
|
| 53 | - */ |
|
| 54 | - protected function getIconFactory() |
|
| 55 | - { |
|
| 56 | - return GeneralUtility::makeInstance(IconFactory::class); |
|
| 57 | - } |
|
| 51 | + /** |
|
| 52 | + * @return IconFactory|object |
|
| 53 | + */ |
|
| 54 | + protected function getIconFactory() |
|
| 55 | + { |
|
| 56 | + return GeneralUtility::makeInstance(IconFactory::class); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return LinkButton|object |
|
| 61 | - */ |
|
| 62 | - protected function makeLinkButton() |
|
| 63 | - { |
|
| 64 | - return GeneralUtility::makeInstance(LinkButton::class); |
|
| 65 | - } |
|
| 59 | + /** |
|
| 60 | + * @return LinkButton|object |
|
| 61 | + */ |
|
| 62 | + protected function makeLinkButton() |
|
| 63 | + { |
|
| 64 | + return GeneralUtility::makeInstance(LinkButton::class); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | } |
@@ -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 | } |