| Total Complexity | 60 |
| Total Lines | 287 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like GridColumnItem often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GridColumnItem, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 39 | class GridColumnItem extends AbstractGridObject |
||
| 40 | { |
||
| 41 | /** |
||
| 42 | * @var mixed[] |
||
| 43 | */ |
||
| 44 | protected $record = []; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var GridColumn |
||
| 48 | */ |
||
| 49 | protected $column; |
||
| 50 | |||
| 51 | public function __construct(BackendLayout $backendLayout, GridColumn $column, array $record) |
||
| 52 | { |
||
| 53 | parent::__construct($backendLayout); |
||
| 54 | $this->column = $column; |
||
| 55 | $this->record = $record; |
||
| 56 | $backendLayout->getRecordRememberer()->rememberRecordUid((int)$record['uid']); |
||
| 57 | $backendLayout->getRecordRememberer()->rememberRecordUid((int)$record['l18n_parent']); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function isVersioned(): bool |
||
| 61 | { |
||
| 62 | return $this->record['_ORIG_uid'] > 0; |
||
| 63 | } |
||
| 64 | |||
| 65 | public function getPreview(): string |
||
| 77 | } |
||
| 78 | |||
| 79 | public function getWrapperClassName(): string |
||
| 80 | { |
||
| 81 | $wrapperClassNames = []; |
||
| 82 | if ($this->isDisabled()) { |
||
| 83 | $wrapperClassNames[] = 't3-page-ce-hidden t3js-hidden-record'; |
||
| 84 | } elseif (!in_array($this->record['colPos'], $this->backendLayout->getColumnPositionNumbers())) { |
||
| 85 | $wrapperClassNames[] = 't3-page-ce-warning'; |
||
| 86 | } |
||
| 87 | |||
| 88 | return implode(' ', $wrapperClassNames); |
||
| 89 | } |
||
| 90 | |||
| 91 | public function isDelible(): bool |
||
| 92 | { |
||
| 93 | $backendUser = $this->getBackendUser(); |
||
| 94 | if (!$backendUser->doesUserHaveAccess($this->backendLayout->getDrawingConfiguration()->getPageRecord(), Permission::CONTENT_EDIT)) { |
||
| 95 | return false; |
||
| 96 | } |
||
| 97 | return !(bool)($backendUser->getTSConfig()['options.']['disableDelete.']['tt_content'] ?? $backendUser->getTSConfig()['options.']['disableDelete'] ?? false); |
||
| 98 | } |
||
| 99 | |||
| 100 | public function getDeleteUrl(): string |
||
| 101 | { |
||
| 102 | $params = '&cmd[tt_content][' . $this->record['uid'] . '][delete]=1'; |
||
| 103 | return BackendUtility::getLinkToDataHandlerAction($params); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function getDeleteTitle(): string |
||
| 107 | { |
||
| 108 | return $this->getLanguageService()->getLL('deleteItem'); |
||
| 109 | } |
||
| 110 | |||
| 111 | public function getDeleteConfirmText(): string |
||
| 112 | { |
||
| 113 | return $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title'); |
||
| 114 | } |
||
| 115 | |||
| 116 | public function getDeleteCancelText(): string |
||
| 117 | { |
||
| 118 | return $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:cancel'); |
||
| 119 | } |
||
| 120 | |||
| 121 | public function getFooterInfo(): string |
||
| 122 | { |
||
| 123 | $record = $this->getRecord(); |
||
| 124 | $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class) |
||
| 125 | ->resolveRendererFor( |
||
| 126 | 'tt_content', |
||
| 127 | $record, |
||
| 128 | $this->backendLayout->getDrawingConfiguration()->getPageId() |
||
| 129 | ); |
||
| 130 | return $previewRenderer->renderPageModulePreviewFooter($this); |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Renders the language flag and language title, but only if an icon is given, otherwise just the language |
||
| 135 | * |
||
| 136 | * @param SiteLanguage $language |
||
| 137 | * @return string |
||
| 138 | */ |
||
| 139 | protected function renderLanguageFlag(SiteLanguage $language) |
||
| 140 | { |
||
| 141 | $title = htmlspecialchars($language->getTitle()); |
||
| 142 | if ($language->getFlagIdentifier()) { |
||
| 143 | $icon = $this->iconFactory->getIcon( |
||
| 144 | $language->getFlagIdentifier(), |
||
| 145 | Icon::SIZE_SMALL |
||
| 146 | )->render(); |
||
| 147 | return '<span title="' . $title . '" class="t3js-flag">' . $icon . '</span> <span class="t3js-language-title">' . $title . '</span>'; |
||
| 148 | } |
||
| 149 | return $title; |
||
| 150 | } |
||
| 151 | |||
| 152 | public function getIcons(): string |
||
| 153 | { |
||
| 154 | $table = 'tt_content'; |
||
| 155 | $row = $this->record; |
||
| 156 | $icons = []; |
||
| 157 | |||
| 158 | $toolTip = BackendUtility::getRecordToolTip($row, $table); |
||
| 159 | $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>'; |
||
| 160 | if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) { |
||
| 161 | $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']); |
||
| 162 | } |
||
| 163 | $icons[] = $icon; |
||
| 164 | $siteLanguage = $this->backendLayout->getDrawingConfiguration()->getSiteLanguage((int)$row['sys_language_uid']); |
||
| 165 | if ($siteLanguage instanceof SiteLanguage) { |
||
| 166 | $icons[] = $this->renderLanguageFlag($siteLanguage); |
||
| 167 | } |
||
| 168 | |||
| 169 | if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) { |
||
| 170 | $icons[] = '<a href="#" data-toggle="tooltip" data-title="' . htmlspecialchars($lockInfo['msg']) . '">' |
||
| 171 | . $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 172 | } |
||
| 173 | |||
| 174 | $_params = ['tt_content', $row['uid'], &$row]; |
||
| 175 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] ?? [] as $_funcRef) { |
||
| 176 | $icons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this); |
||
| 177 | } |
||
| 178 | return implode(' ', $icons); |
||
| 179 | } |
||
| 180 | |||
| 181 | public function getRecord(): array |
||
| 184 | } |
||
| 185 | |||
| 186 | public function setRecord(array $record): void |
||
| 187 | { |
||
| 188 | $this->record = $record; |
||
| 189 | } |
||
| 190 | |||
| 191 | public function getColumn(): GridColumn |
||
| 192 | { |
||
| 193 | return $this->column; |
||
| 194 | } |
||
| 195 | |||
| 196 | public function isDisabled(): bool |
||
| 197 | { |
||
| 198 | $table = 'tt_content'; |
||
| 199 | $row = $this->getRecord(); |
||
| 200 | $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']; |
||
| 201 | return $enableCols['disabled'] && $row[$enableCols['disabled']] |
||
| 202 | || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME'] |
||
| 203 | || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME']; |
||
| 204 | } |
||
| 205 | |||
| 206 | public function hasTranslation(): bool |
||
| 207 | { |
||
| 208 | $contentElements = $this->column->getRecords(); |
||
| 209 | $id = $this->backendLayout->getDrawingConfiguration()->getPageId(); |
||
| 210 | $language = $this->backendLayout->getDrawingConfiguration()->getLanguageColumnsPointer(); |
||
| 211 | // If in default language, you may always create new entries |
||
| 212 | // Also, you may override this strict behavior via user TS Config |
||
| 213 | // If you do so, you're on your own and cannot rely on any support by the TYPO3 core. |
||
| 214 | $allowInconsistentLanguageHandling = (bool)(BackendUtility::getPagesTSconfig($id)['mod.']['web_layout.']['allowInconsistentLanguageHandling'] ?? false); |
||
| 215 | if ($language === 0 || $allowInconsistentLanguageHandling) { |
||
| 216 | return false; |
||
| 217 | } |
||
| 218 | |||
| 219 | return $this->backendLayout->getContentFetcher()->getTranslationData($contentElements, $language)['hasTranslations'] ?? false; |
||
| 220 | } |
||
| 221 | |||
| 222 | public function isDeletePlaceholder(): bool |
||
| 225 | } |
||
| 226 | |||
| 227 | public function isEditable(): bool |
||
| 228 | { |
||
| 229 | $languageId = $this->backendLayout->getDrawingConfiguration()->getLanguageColumnsPointer(); |
||
| 230 | if ($this->getBackendUser()->isAdmin()) { |
||
| 231 | return true; |
||
| 232 | } |
||
| 233 | $pageRecord = $this->backendLayout->getDrawingConfiguration()->getPageRecord(); |
||
| 234 | return !$pageRecord['editlock'] |
||
| 235 | && $this->getBackendUser()->doesUserHaveAccess($pageRecord, Permission::CONTENT_EDIT) |
||
| 236 | && ($languageId === null || $this->getBackendUser()->checkLanguageAccess($languageId)); |
||
| 237 | } |
||
| 238 | |||
| 239 | public function isDragAndDropAllowed(): bool |
||
| 240 | { |
||
| 241 | $pageRecord = $this->backendLayout->getDrawingConfiguration()->getPageRecord(); |
||
| 242 | return (int)$this->record['l18n_parent'] === 0 && |
||
| 243 | ( |
||
| 244 | $this->getBackendUser()->isAdmin() |
||
| 245 | || ((int)$this->record['editlock'] === 0 && (int)$pageRecord['editlock'] === 0) |
||
| 246 | && $this->getBackendUser()->doesUserHaveAccess($pageRecord, Permission::CONTENT_EDIT) |
||
| 247 | && $this->getBackendUser()->checkAuthMode('tt_content', 'CType', $this->record['CType'], $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode']) |
||
| 248 | ) |
||
| 249 | ; |
||
|
|
|||
| 250 | } |
||
| 251 | |||
| 252 | public function getNewContentAfterLinkTitle(): string |
||
| 253 | { |
||
| 254 | return $this->getLanguageService()->getLL('newContentElement'); |
||
| 255 | } |
||
| 256 | |||
| 257 | public function getNewContentAfterTitle(): string |
||
| 258 | { |
||
| 259 | return $this->getLanguageService()->getLL('content'); |
||
| 260 | } |
||
| 261 | |||
| 262 | public function getNewContentAfterUrl(): string |
||
| 263 | { |
||
| 264 | $pageId = $this->backendLayout->getDrawingConfiguration()->getPageId(); |
||
| 265 | $urlParameters = [ |
||
| 266 | 'id' => $pageId, |
||
| 267 | 'sys_language_uid' => $this->backendLayout->getDrawingConfiguration()->getLanguageColumnsPointer(), |
||
| 268 | 'colPos' => $this->column->getColumnNumber(), |
||
| 269 | 'uid_pid' => -$this->record['uid'], |
||
| 270 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
| 271 | ]; |
||
| 272 | $routeName = BackendUtility::getPagesTSconfig($pageId)['mod.']['newContentElementWizard.']['override'] |
||
| 273 | ?? 'new_content_element_wizard'; |
||
| 274 | $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
||
| 275 | return (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters); |
||
| 276 | } |
||
| 277 | |||
| 278 | public function getVisibilityToggleUrl(): string |
||
| 289 | } |
||
| 290 | |||
| 291 | public function getVisibilityToggleTitle(): string |
||
| 292 | { |
||
| 293 | $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled']; |
||
| 294 | return $this->getLanguageService()->getLL($this->record[$hiddenField] ? 'unhide' : 'hide'); |
||
| 295 | } |
||
| 296 | |||
| 297 | public function getVisibilityToggleIconName(): string |
||
| 301 | } |
||
| 302 | |||
| 303 | public function isVisibilityToggling(): bool |
||
| 304 | { |
||
| 305 | $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled']; |
||
| 306 | return $hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField] |
||
| 307 | && ( |
||
| 308 | !$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude'] |
||
| 309 | || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField) |
||
| 310 | ) |
||
| 311 | ; |
||
| 312 | } |
||
| 313 | |||
| 314 | public function getEditUrl(): string |
||
| 326 | } |
||
| 327 | } |
||
| 328 |