| Total Complexity | 59 |
| Total Lines | 294 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| 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 |
||
| 41 | class GridColumnItem extends AbstractGridObject |
||
| 42 | { |
||
| 43 | /** |
||
| 44 | * @var mixed[] |
||
| 45 | */ |
||
| 46 | protected $record = []; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var GridColumn |
||
| 50 | */ |
||
| 51 | protected $column; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var GridColumnItem[] |
||
| 55 | */ |
||
| 56 | protected $translations = []; |
||
| 57 | |||
| 58 | public function __construct(PageLayoutContext $context, GridColumn $column, array $record) |
||
| 59 | { |
||
| 60 | parent::__construct($context); |
||
| 61 | $this->column = $column; |
||
| 62 | $this->record = $record; |
||
| 63 | } |
||
| 64 | |||
| 65 | public function isVersioned(): bool |
||
| 66 | { |
||
| 67 | return $this->record['_ORIG_uid'] > 0 || (int)$this->record['t3ver_state'] !== 0; |
||
| 68 | } |
||
| 69 | |||
| 70 | public function getPreview(): string |
||
| 71 | { |
||
| 72 | $record = $this->getRecord(); |
||
| 73 | $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class) |
||
| 74 | ->resolveRendererFor( |
||
| 75 | 'tt_content', |
||
| 76 | $record, |
||
| 77 | $this->context->getPageId() |
||
| 78 | ); |
||
| 79 | $previewHeader = $previewRenderer->renderPageModulePreviewHeader($this); |
||
| 80 | $previewContent = $previewRenderer->renderPageModulePreviewContent($this); |
||
| 81 | return $previewRenderer->wrapPageModulePreview($previewHeader, $previewContent, $this); |
||
| 82 | } |
||
| 83 | |||
| 84 | public function getWrapperClassName(): string |
||
| 85 | { |
||
| 86 | $wrapperClassNames = []; |
||
| 87 | if ($this->isDisabled()) { |
||
| 88 | $wrapperClassNames[] = 't3-page-ce-hidden t3js-hidden-record'; |
||
| 89 | } elseif (!in_array($this->record['colPos'], $this->context->getBackendLayout()->getColumnPositionNumbers())) { |
||
| 90 | $wrapperClassNames[] = 't3-page-ce-warning'; |
||
| 91 | } |
||
| 92 | |||
| 93 | return implode(' ', $wrapperClassNames); |
||
| 94 | } |
||
| 95 | |||
| 96 | public function isDelible(): bool |
||
| 97 | { |
||
| 98 | $backendUser = $this->getBackendUser(); |
||
| 99 | if (!$backendUser->doesUserHaveAccess($this->context->getPageRecord(), Permission::CONTENT_EDIT)) { |
||
| 100 | return false; |
||
| 101 | } |
||
| 102 | return !(bool)($backendUser->getTSConfig()['options.']['disableDelete.']['tt_content'] ?? $backendUser->getTSConfig()['options.']['disableDelete'] ?? false); |
||
| 103 | } |
||
| 104 | |||
| 105 | public function getDeleteUrl(): string |
||
| 106 | { |
||
| 107 | $params = '&cmd[tt_content][' . $this->record['uid'] . '][delete]=1'; |
||
| 108 | return BackendUtility::getLinkToDataHandlerAction($params); |
||
| 109 | } |
||
| 110 | |||
| 111 | public function getDeleteTitle(): string |
||
| 112 | { |
||
| 113 | return $this->getLanguageService()->getLL('deleteItem'); |
||
| 114 | } |
||
| 115 | |||
| 116 | public function getDeleteConfirmText(): string |
||
| 117 | { |
||
| 118 | return $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title'); |
||
| 119 | } |
||
| 120 | |||
| 121 | public function getDeleteCancelText(): string |
||
| 122 | { |
||
| 123 | return $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:cancel'); |
||
| 124 | } |
||
| 125 | |||
| 126 | public function getFooterInfo(): string |
||
| 127 | { |
||
| 128 | $record = $this->getRecord(); |
||
| 129 | $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class) |
||
| 130 | ->resolveRendererFor( |
||
| 131 | 'tt_content', |
||
| 132 | $record, |
||
| 133 | $this->context->getPageId() |
||
| 134 | ); |
||
| 135 | return $previewRenderer->renderPageModulePreviewFooter($this); |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Renders the language flag and language title, but only if an icon is given, otherwise just the language |
||
| 140 | * |
||
| 141 | * @param SiteLanguage $language |
||
| 142 | * @return string |
||
| 143 | */ |
||
| 144 | protected function renderLanguageFlag(SiteLanguage $language) |
||
| 145 | { |
||
| 146 | $title = htmlspecialchars($language->getTitle()); |
||
| 147 | if ($language->getFlagIdentifier()) { |
||
| 148 | $icon = $this->iconFactory->getIcon( |
||
| 149 | $language->getFlagIdentifier(), |
||
| 150 | Icon::SIZE_SMALL |
||
| 151 | )->render(); |
||
| 152 | return '<span title="' . $title . '" class="t3js-flag">' . $icon . '</span> <span class="t3js-language-title">' . $title . '</span>'; |
||
| 153 | } |
||
| 154 | return $title; |
||
| 155 | } |
||
| 156 | |||
| 157 | public function getIcons(): string |
||
| 158 | { |
||
| 159 | $table = 'tt_content'; |
||
| 160 | $row = $this->record; |
||
| 161 | $icons = []; |
||
| 162 | |||
| 163 | $toolTip = BackendUtility::getRecordToolTip($row, $table); |
||
| 164 | $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>'; |
||
| 165 | if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) { |
||
| 166 | $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']); |
||
| 167 | } |
||
| 168 | $icons[] = $icon; |
||
| 169 | $siteLanguage = $this->context->getSiteLanguage((int)$row['sys_language_uid']); |
||
| 170 | if ($siteLanguage instanceof SiteLanguage) { |
||
|
|
|||
| 171 | $icons[] = $this->renderLanguageFlag($siteLanguage); |
||
| 172 | } |
||
| 173 | |||
| 174 | if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) { |
||
| 175 | $icons[] = '<a href="#" data-bs-toggle="tooltip" data-title="' . htmlspecialchars($lockInfo['msg']) . '">' |
||
| 176 | . $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 177 | } |
||
| 178 | |||
| 179 | $_params = ['tt_content', $row['uid'], &$row]; |
||
| 180 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] ?? [] as $_funcRef) { |
||
| 181 | $icons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this); |
||
| 182 | } |
||
| 183 | return implode(' ', $icons); |
||
| 184 | } |
||
| 185 | |||
| 186 | public function getRecord(): array |
||
| 187 | { |
||
| 188 | return $this->record; |
||
| 189 | } |
||
| 190 | |||
| 191 | public function setRecord(array $record): void |
||
| 192 | { |
||
| 193 | $this->record = $record; |
||
| 194 | } |
||
| 195 | |||
| 196 | public function getColumn(): GridColumn |
||
| 197 | { |
||
| 198 | return $this->column; |
||
| 199 | } |
||
| 200 | |||
| 201 | public function getTranslations(): array |
||
| 202 | { |
||
| 203 | return $this->translations; |
||
| 204 | } |
||
| 205 | |||
| 206 | public function addTranslation(int $languageId, GridColumnItem $translation): GridColumnItem |
||
| 207 | { |
||
| 208 | $this->translations[$languageId] = $translation; |
||
| 209 | return $this; |
||
| 210 | } |
||
| 211 | |||
| 212 | public function isDisabled(): bool |
||
| 220 | } |
||
| 221 | |||
| 222 | public function isEditable(): bool |
||
| 223 | { |
||
| 224 | $backendUser = $this->getBackendUser(); |
||
| 225 | if ($backendUser->isAdmin()) { |
||
| 226 | return true; |
||
| 227 | } |
||
| 228 | $pageRecord = $this->context->getPageRecord(); |
||
| 229 | return !(bool)($pageRecord['editlock'] ?? false) |
||
| 230 | && $backendUser->doesUserHaveAccess($pageRecord, Permission::CONTENT_EDIT) |
||
| 231 | && $backendUser->recordEditAccessInternals('tt_content', $this->record); |
||
| 232 | } |
||
| 233 | |||
| 234 | public function isDragAndDropAllowed(): bool |
||
| 235 | { |
||
| 236 | $pageRecord = $this->context->getPageRecord(); |
||
| 237 | return (int)$this->record['l18n_parent'] === 0 && |
||
| 238 | ( |
||
| 239 | $this->getBackendUser()->isAdmin() |
||
| 240 | || ((int)$this->record['editlock'] === 0 && (int)$pageRecord['editlock'] === 0) |
||
| 241 | && $this->getBackendUser()->doesUserHaveAccess($pageRecord, Permission::CONTENT_EDIT) |
||
| 242 | && $this->getBackendUser()->checkAuthMode('tt_content', 'CType', $this->record['CType'], $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode']) |
||
| 243 | ) |
||
| 244 | ; |
||
| 245 | } |
||
| 246 | |||
| 247 | public function getNewContentAfterLinkTitle(): string |
||
| 248 | { |
||
| 249 | return $this->getLanguageService()->getLL('newContentElement'); |
||
| 250 | } |
||
| 251 | |||
| 252 | public function getNewContentAfterTitle(): string |
||
| 253 | { |
||
| 254 | return $this->getLanguageService()->getLL('content'); |
||
| 255 | } |
||
| 256 | |||
| 257 | public function getNewContentAfterUrl(): string |
||
| 258 | { |
||
| 259 | $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
||
| 260 | $pageId = $this->context->getPageId(); |
||
| 261 | |||
| 262 | if ($this->context->getDrawingConfiguration()->getShowNewContentWizard()) { |
||
| 263 | $urlParameters = [ |
||
| 264 | 'id' => $pageId, |
||
| 265 | 'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId(), |
||
| 266 | 'colPos' => $this->column->getColumnNumber(), |
||
| 267 | 'uid_pid' => -$this->record['uid'], |
||
| 268 | 'returnUrl' => $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri() |
||
| 269 | ]; |
||
| 270 | $routeName = BackendUtility::getPagesTSconfig($pageId)['mod.']['newContentElementWizard.']['override'] |
||
| 271 | ?? 'new_content_element_wizard'; |
||
| 272 | } else { |
||
| 273 | $urlParameters = [ |
||
| 274 | 'edit' => [ |
||
| 275 | 'tt_content' => [ |
||
| 276 | -$this->record['uid'] => 'new' |
||
| 277 | ] |
||
| 278 | ], |
||
| 279 | 'returnUrl' => $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri() |
||
| 280 | ]; |
||
| 281 | $routeName = 'record_edit'; |
||
| 282 | } |
||
| 283 | |||
| 284 | return (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters); |
||
| 285 | } |
||
| 286 | |||
| 287 | public function getVisibilityToggleUrl(): string |
||
| 298 | } |
||
| 299 | |||
| 300 | public function getVisibilityToggleTitle(): string |
||
| 301 | { |
||
| 302 | $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled']; |
||
| 303 | return $this->getLanguageService()->getLL($this->record[$hiddenField] ? 'unhide' : 'hide'); |
||
| 304 | } |
||
| 305 | |||
| 306 | public function getVisibilityToggleIconName(): string |
||
| 310 | } |
||
| 311 | |||
| 312 | public function isVisibilityToggling(): bool |
||
| 313 | { |
||
| 314 | $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled']; |
||
| 315 | return $hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField] |
||
| 316 | && ( |
||
| 317 | !$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude'] |
||
| 318 | || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField) |
||
| 319 | ) |
||
| 320 | ; |
||
| 321 | } |
||
| 322 | |||
| 323 | public function getEditUrl(): string |
||
| 335 | } |
||
| 336 | } |
||
| 337 |