| Conditions | 31 |
| Paths | 97 |
| Total Lines | 135 |
| Code Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 98 | public function renderPageModulePreviewContent(GridColumnItem $item): string |
||
| 99 | { |
||
| 100 | $out = ''; |
||
| 101 | $record = $item->getRecord(); |
||
| 102 | |||
| 103 | $contentTypeLabels = $item->getContext()->getContentTypeLabels(); |
||
| 104 | $languageService = $this->getLanguageService(); |
||
| 105 | |||
| 106 | $drawItem = true; |
||
| 107 | $hookPreviewContent = ''; |
||
| 108 | // Hook: Render an own preview of a record |
||
| 109 | if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'])) { |
||
| 110 | $pageLayoutView = PageLayoutView::createFromPageLayoutContext($item->getContext()); |
||
| 111 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'] ?? [] as $className) { |
||
| 112 | $hookObject = GeneralUtility::makeInstance($className); |
||
| 113 | if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) { |
||
| 114 | throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1582574553); |
||
| 115 | } |
||
| 116 | $hookObject->preProcess($pageLayoutView, $drawItem, $previewHeader, $hookPreviewContent, $record); |
||
| 117 | } |
||
| 118 | $item->setRecord($record); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (!$drawItem) { |
||
| 122 | return $hookPreviewContent; |
||
| 123 | } |
||
| 124 | // Check if a Fluid-based preview template was defined for this CType |
||
| 125 | // and render it via Fluid. Possible option: |
||
| 126 | // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html |
||
| 127 | $infoArr = []; |
||
| 128 | $this->getProcessedValue($item, 'header_position,header_layout,header_link', $infoArr); |
||
| 129 | $tsConfig = BackendUtility::getPagesTSconfig($record['pid'])['mod.']['web_layout.']['tt_content.']['preview.'] ?? []; |
||
| 130 | if (!empty($tsConfig[$record['CType']]) || !empty($tsConfig[$record['CType'] . '.'])) { |
||
| 131 | $fluidPreview = $this->renderContentElementPreviewFromFluidTemplate($record); |
||
| 132 | if ($fluidPreview !== null) { |
||
| 133 | return $fluidPreview; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | // Draw preview of the item depending on its CType |
||
| 138 | switch ($record['CType']) { |
||
| 139 | case 'header': |
||
| 140 | if ($record['subheader']) { |
||
| 141 | $out .= $this->linkEditContent($this->renderText($record['subheader']), $record) . '<br />'; |
||
| 142 | } |
||
| 143 | break; |
||
| 144 | case 'uploads': |
||
| 145 | if ($record['media']) { |
||
| 146 | $out .= $this->linkEditContent($this->getThumbCodeUnlinked($record, 'tt_content', 'media'), $record) . '<br />'; |
||
| 147 | } |
||
| 148 | break; |
||
| 149 | case 'shortcut': |
||
| 150 | if (!empty($record['records'])) { |
||
| 151 | $shortcutContent = []; |
||
| 152 | $recordList = explode(',', $record['records']); |
||
| 153 | foreach ($recordList as $recordIdentifier) { |
||
| 154 | $split = BackendUtility::splitTable_Uid($recordIdentifier); |
||
| 155 | $tableName = empty($split[0]) ? 'tt_content' : $split[0]; |
||
| 156 | $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]); |
||
|
|
|||
| 157 | if (is_array($shortcutRecord)) { |
||
| 158 | $icon = $this->getIconFactory()->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render(); |
||
| 159 | $icon = BackendUtility::wrapClickMenuOnIcon( |
||
| 160 | $icon, |
||
| 161 | $tableName, |
||
| 162 | $shortcutRecord['uid'], |
||
| 163 | '1' |
||
| 164 | ); |
||
| 165 | $shortcutContent[] = $icon |
||
| 166 | . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord)); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | $out .= implode('<br />', $shortcutContent) . '<br />'; |
||
| 170 | } |
||
| 171 | break; |
||
| 172 | case 'list': |
||
| 173 | $hookOut = ''; |
||
| 174 | if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'])) { |
||
| 175 | $pageLayoutView = PageLayoutView::createFromPageLayoutContext($item->getContext()); |
||
| 176 | $_params = ['pObj' => &$pageLayoutView, 'row' => $record]; |
||
| 177 | foreach ( |
||
| 178 | $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$record['list_type']] ?? |
||
| 179 | $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'] ?? |
||
| 180 | [] as $_funcRef |
||
| 181 | ) { |
||
| 182 | $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $pageLayoutView); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | if ((string)$hookOut !== '') { |
||
| 187 | $out .= $hookOut; |
||
| 188 | } elseif (!empty($record['list_type'])) { |
||
| 189 | $label = BackendUtility::getLabelFromItemListMerged($record['pid'], 'tt_content', 'list_type', $record['list_type']); |
||
| 190 | if (!empty($label)) { |
||
| 191 | $out .= $this->linkEditContent('<strong>' . htmlspecialchars($languageService->sL($label)) . '</strong>', $record) . '<br />'; |
||
| 192 | } else { |
||
| 193 | $message = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'), $record['list_type']); |
||
| 194 | $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>'; |
||
| 195 | } |
||
| 196 | } elseif (!empty($record['select_key'])) { |
||
| 197 | $out .= htmlspecialchars($languageService->sL(BackendUtility::getItemLabel('tt_content', 'select_key'))) |
||
| 198 | . ' ' . htmlspecialchars($record['select_key']) . '<br />'; |
||
| 199 | } else { |
||
| 200 | $out .= '<strong>' . $languageService->getLL('noPluginSelected') . '</strong>'; |
||
| 201 | } |
||
| 202 | $out .= htmlspecialchars($languageService->sL(BackendUtility::getLabelFromItemlist('tt_content', 'pages', $record['pages']))) . '<br />'; |
||
| 203 | break; |
||
| 204 | default: |
||
| 205 | $contentTypeLabel = (string)($contentTypeLabels[$record['CType']] ?? ''); |
||
| 206 | if ($contentTypeLabel === '') { |
||
| 207 | $message = sprintf( |
||
| 208 | $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'), |
||
| 209 | $record['CType'] |
||
| 210 | ); |
||
| 211 | $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>'; |
||
| 212 | break; |
||
| 213 | } |
||
| 214 | // Handle menu content types |
||
| 215 | if (in_array($record['CType'], self::MENU_CONTENT_TYPES, true)) { |
||
| 216 | $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentTypeLabel) . '</strong>', $record); |
||
| 217 | if ($record['CType'] !== 'menu_sitemap' && (($record['pages'] ?? false) || ($record['selected_categories'] ?? false))) { |
||
| 218 | // Show pages/categories if menu type is not "Sitemap" |
||
| 219 | $out .= ':' . $this->linkEditContent($this->generateListForMenuContentTypes($record), $record) . '<br />'; |
||
| 220 | } |
||
| 221 | break; |
||
| 222 | } |
||
| 223 | $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentTypeLabel) . '</strong>', $record) . '<br />'; |
||
| 224 | if ($record['bodytext']) { |
||
| 225 | $out .= $this->linkEditContent($this->renderText($record['bodytext']), $record) . '<br />'; |
||
| 226 | } |
||
| 227 | if ($record['image']) { |
||
| 228 | $out .= $this->linkEditContent($this->getThumbCodeUnlinked($record, 'tt_content', 'image'), $record) . '<br />'; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | return $out; |
||
| 233 | } |
||
| 442 |