Conditions | 11 |
Paths | 5 |
Total Lines | 74 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
66 | public function mainAction(ServerRequestInterface $request): ResponseInterface |
||
67 | { |
||
68 | $backendUser = $this->getBackendUser(); |
||
69 | $parentPageUid = (int)$request->getQueryParams()['id']; |
||
70 | |||
71 | // Show only if there is a valid page and if this page may be viewed by the user |
||
72 | $pageInformation = BackendUtility::readPageAccess($parentPageUid, $backendUser->getPagePermsClause(Permission::PAGE_SHOW)); |
||
73 | if (!is_array($pageInformation)) { |
||
74 | // User has no permission on parent page, should not happen, just render an empty page |
||
75 | $this->moduleTemplate->setContent(''); |
||
76 | return new HtmlResponse($this->moduleTemplate->renderContent()); |
||
77 | } |
||
78 | |||
79 | // Doc header handling |
||
80 | $iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
||
81 | $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageInformation); |
||
82 | $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
||
83 | $cshButton = $buttonBar->makeHelpButton() |
||
84 | ->setModuleName('pages_sort') |
||
85 | ->setFieldName('pages_sort'); |
||
86 | $previewDataAttributes = PreviewUriBuilder::create($parentPageUid) |
||
87 | ->withRootLine(BackendUtility::BEgetRootLine($parentPageUid)) |
||
88 | ->buildDispatcherDataAttributes(); |
||
89 | $viewButton = $buttonBar->makeLinkButton() |
||
90 | ->setDataAttributes($previewDataAttributes ?? []) |
||
91 | ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage')) |
||
92 | ->setIcon($iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)) |
||
93 | ->setHref('#'); |
||
94 | $buttonBar->addButton($cshButton)->addButton($viewButton); |
||
95 | |||
96 | // Main view setup |
||
97 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
||
98 | $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( |
||
99 | 'EXT:backend/Resources/Private/Templates/Page/SortSubPages.html' |
||
100 | )); |
||
101 | |||
102 | $isInWorkspace = $backendUser->workspace !== 0; |
||
103 | $view->assign('isInWorkspace', $isInWorkspace); |
||
104 | $view->assign('maxTitleLength', $backendUser->uc['titleLen'] ?? 20); |
||
105 | $view->assign('parentPageUid', $parentPageUid); |
||
106 | $view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']); |
||
107 | $view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']); |
||
108 | |||
109 | if (!$isInWorkspace) { |
||
110 | // Apply new sorting if given |
||
111 | $newSortBy = $request->getQueryParams()['newSortBy'] ?? null; |
||
112 | if ($newSortBy && in_array($newSortBy, ['title', 'subtitle', 'nav_title', 'crdate', 'tstamp'], true)) { |
||
113 | $this->sortSubPagesByField($parentPageUid, (string)$newSortBy); |
||
114 | } elseif ($newSortBy && $newSortBy === 'reverseCurrentSorting') { |
||
115 | $this->reverseSortingOfPages($parentPageUid); |
||
116 | } |
||
117 | |||
118 | // Get sub pages, loop through them and add page/user specific permission details |
||
119 | $pageRecords = $this->getSubPagesOfPage($parentPageUid); |
||
120 | $hasInvisiblePage = false; |
||
121 | $subPages = []; |
||
122 | foreach ($pageRecords as $page) { |
||
123 | $pageWithPermissions = []; |
||
124 | $pageWithPermissions['record'] = $page; |
||
125 | $calculatedPermissions = new Permission($backendUser->calcPerms($page)); |
||
126 | $pageWithPermissions['canEdit'] = $backendUser->isAdmin() || $calculatedPermissions->editPagePermissionIsGranted(); |
||
127 | $canSeePage = $backendUser->isAdmin() || $calculatedPermissions->showPagePermissionIsGranted(); |
||
128 | if ($canSeePage) { |
||
129 | $subPages[] = $pageWithPermissions; |
||
130 | } else { |
||
131 | $hasInvisiblePage = true; |
||
132 | } |
||
133 | } |
||
134 | $view->assign('subPages', $subPages); |
||
135 | $view->assign('hasInvisiblePage', $hasInvisiblePage); |
||
136 | } |
||
137 | |||
138 | $this->moduleTemplate->setContent($view->render()); |
||
139 | return new HtmlResponse($this->moduleTemplate->renderContent()); |
||
140 | } |
||
241 |