| Conditions | 31 |
| Paths | 97 |
| Total Lines | 143 |
| Code Lines | 102 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 77 | public function renderPageModulePreviewContent(GridColumnItem $item): string |
||
| 78 | { |
||
| 79 | $out = ''; |
||
| 80 | $record = $item->getRecord(); |
||
| 81 | |||
| 82 | $contentTypeLabels = $item->getBackendLayout()->getDrawingConfiguration()->getContentTypeLabels(); |
||
| 83 | $languageService = $this->getLanguageService(); |
||
| 84 | |||
| 85 | $drawItem = true; |
||
| 86 | $hookPreviewContent = ''; |
||
| 87 | // Hook: Render an own preview of a record |
||
| 88 | if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'])) { |
||
| 89 | $pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration()); |
||
| 90 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'] ?? [] as $className) { |
||
| 91 | $hookObject = GeneralUtility::makeInstance($className); |
||
| 92 | if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) { |
||
| 93 | throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1582574553); |
||
| 94 | } |
||
| 95 | $hookObject->preProcess($pageLayoutView, $drawItem, $previewHeader, $hookPreviewContent, $record); |
||
| 96 | } |
||
| 97 | $item->setRecord($record); |
||
| 98 | } |
||
| 99 | |||
| 100 | if (!$drawItem) { |
||
| 101 | return $hookPreviewContent; |
||
| 102 | } |
||
| 103 | // Check if a Fluid-based preview template was defined for this CType |
||
| 104 | // and render it via Fluid. Possible option: |
||
| 105 | // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html |
||
| 106 | $infoArr = []; |
||
| 107 | $this->getProcessedValue($item, 'header_position,header_layout,header_link', $infoArr); |
||
| 108 | $tsConfig = BackendUtility::getPagesTSconfig($record['pid'])['mod.']['web_layout.']['tt_content.']['preview.'] ?? []; |
||
| 109 | if (!empty($tsConfig[$record['CType']])) { |
||
| 110 | $fluidPreview = $this->renderContentElementPreviewFromFluidTemplate($record); |
||
| 111 | if ($fluidPreview !== null) { |
||
| 112 | return $fluidPreview; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | // Draw preview of the item depending on its CType |
||
| 117 | switch ($record['CType']) { |
||
| 118 | case 'header': |
||
| 119 | if ($record['subheader']) { |
||
| 120 | $out .= $this->linkEditContent($this->renderText($record['subheader']), $record) . '<br />'; |
||
| 121 | } |
||
| 122 | break; |
||
| 123 | case 'uploads': |
||
| 124 | if ($record['media']) { |
||
| 125 | $out .= $this->linkEditContent($this->getThumbCodeUnlinked($record, 'tt_content', 'media'), $record) . '<br />'; |
||
| 126 | } |
||
| 127 | break; |
||
| 128 | case 'menu': |
||
| 129 | $contentType = $contentTypeLabels[$record['CType']]; |
||
| 130 | $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $record) . '<br />'; |
||
| 131 | // Add Menu Type |
||
| 132 | $menuTypeLabel = $languageService->sL( |
||
| 133 | BackendUtility::getLabelFromItemListMerged($record['pid'], 'tt_content', 'menu_type', $record['menu_type']) |
||
| 134 | ); |
||
| 135 | $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type'; |
||
| 136 | $out .= $this->linkEditContent($menuTypeLabel, $record); |
||
| 137 | if ($record['menu_type'] !== '2' && ($record['pages'] || $record['selected_categories'])) { |
||
| 138 | // Show pages if menu type is not "Sitemap" |
||
| 139 | $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($record), $record) . '<br />'; |
||
| 140 | } |
||
| 141 | break; |
||
| 142 | case 'shortcut': |
||
| 143 | if (!empty($record['records'])) { |
||
| 144 | $shortcutContent = []; |
||
| 145 | $recordList = explode(',', $record['records']); |
||
| 146 | foreach ($recordList as $recordIdentifier) { |
||
| 147 | $split = BackendUtility::splitTable_Uid($recordIdentifier); |
||
| 148 | $tableName = empty($split[0]) ? 'tt_content' : $split[0]; |
||
| 149 | $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]); |
||
| 150 | if (is_array($shortcutRecord)) { |
||
| 151 | $icon = $this->getIconFactory()->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render(); |
||
| 152 | $icon = BackendUtility::wrapClickMenuOnIcon( |
||
| 153 | $icon, |
||
| 154 | $tableName, |
||
| 155 | $shortcutRecord['uid'], |
||
| 156 | 1, |
||
| 157 | '', |
||
| 158 | '+copy,info,edit,view' |
||
| 159 | ); |
||
| 160 | $shortcutContent[] = $icon |
||
| 161 | . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord)); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | $out .= implode('<br />', $shortcutContent) . '<br />'; |
||
| 165 | } |
||
| 166 | break; |
||
| 167 | case 'list': |
||
| 168 | $hookOut = ''; |
||
| 169 | if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'])) { |
||
| 170 | $pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration()); |
||
| 171 | $_params = ['pObj' => &$pageLayoutView, 'row' => $record]; |
||
| 172 | foreach ( |
||
| 173 | $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$record['list_type']] ?? |
||
| 174 | $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'] ?? |
||
| 175 | [] as $_funcRef |
||
| 176 | ) { |
||
| 177 | $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $pageLayoutView); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | if ((string)$hookOut !== '') { |
||
| 182 | $out .= $hookOut; |
||
| 183 | } elseif (!empty($record['list_type'])) { |
||
| 184 | $label = BackendUtility::getLabelFromItemListMerged($record['pid'], 'tt_content', 'list_type', $record['list_type']); |
||
| 185 | if (!empty($label)) { |
||
| 186 | $out .= $this->linkEditContent('<strong>' . htmlspecialchars($languageService->sL($label)) . '</strong>', $record) . '<br />'; |
||
| 187 | } else { |
||
| 188 | $message = sprintf($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $record['list_type']); |
||
| 189 | $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>'; |
||
| 190 | } |
||
| 191 | } elseif (!empty($record['select_key'])) { |
||
| 192 | $out .= htmlspecialchars($languageService->sL(BackendUtility::getItemLabel('tt_content', 'select_key'))) |
||
| 193 | . ' ' . htmlspecialchars($record['select_key']) . '<br />'; |
||
| 194 | } else { |
||
| 195 | $out .= '<strong>' . $languageService->getLL('noPluginSelected') . '</strong>'; |
||
| 196 | } |
||
| 197 | $out .= htmlspecialchars($languageService->sL(BackendUtility::getLabelFromItemlist('tt_content', 'pages', $record['pages']))) . '<br />'; |
||
| 198 | break; |
||
| 199 | default: |
||
| 200 | $contentType = $contentTypeLabels[$record['CType']]; |
||
| 201 | |||
| 202 | if (isset($contentType)) { |
||
| 203 | $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $record) . '<br />'; |
||
| 204 | if ($record['bodytext']) { |
||
| 205 | $out .= $this->linkEditContent($this->renderText($record['bodytext']), $record) . '<br />'; |
||
| 206 | } |
||
| 207 | if ($record['image']) { |
||
| 208 | $out .= $this->linkEditContent($this->getThumbCodeUnlinked($record, 'tt_content', 'image'), $record) . '<br />'; |
||
| 209 | } |
||
| 210 | } else { |
||
| 211 | $message = sprintf( |
||
| 212 | $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), |
||
| 213 | $record['CType'] |
||
| 214 | ); |
||
| 215 | $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>'; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | return $out; |
||
| 220 | } |
||
| 429 |