Conditions | 12 |
Paths | 144 |
Total Lines | 200 |
Code Lines | 151 |
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 |
||
46 | public function createToolbar(): string |
||
47 | { |
||
48 | /** @var LanguageAspect $languageAspect */ |
||
49 | $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language'); |
||
50 | $iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
||
51 | $tsfe = $this->getTypoScriptFrontendController(); |
||
52 | // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead: |
||
53 | $moduleName = BackendUtility::getPagesTSconfig($tsfe->page['uid'])['mod.']['newContentElementWizard.']['override'] ?? 'new_content_element'; |
||
54 | $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
||
55 | $perms = $this->getBackendUser()->calcPerms($tsfe->page); |
||
56 | $langAllowed = $this->getBackendUser()->checkLanguageAccess($languageAspect->getId()); |
||
57 | $id = $tsfe->id; |
||
58 | $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI'); |
||
59 | $classes = 'typo3-adminPanel-btn typo3-adminPanel-btn-default'; |
||
60 | $output = []; |
||
61 | $output[] = '<div class="typo3-adminPanel-form-group">'; |
||
62 | $output[] = ' <div class="typo3-adminPanel-btn-group" role="group">'; |
||
63 | |||
64 | // History |
||
65 | $link = (string)$uriBuilder->buildUriFromRoute( |
||
66 | 'record_history', |
||
67 | [ |
||
68 | 'element' => 'pages:' . $id, |
||
69 | 'returnUrl' => $returnUrl, |
||
70 | ] |
||
71 | ); |
||
72 | $title = $this->getLabel('edit_recordHistory'); |
||
73 | $output[] = '<a class="' . |
||
74 | $classes . |
||
75 | '" href="' . |
||
76 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
77 | '#latest" title="' . |
||
78 | $title . |
||
79 | '">'; |
||
80 | $output[] = ' ' . $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render(); |
||
81 | $output[] = '</a>'; |
||
82 | |||
83 | // New Content |
||
84 | if ($perms & Permission::CONTENT_EDIT && $langAllowed) { |
||
85 | $linkParameters = [ |
||
86 | 'id' => $id, |
||
87 | 'returnUrl' => $returnUrl, |
||
88 | ]; |
||
89 | if (!empty($languageAspect->getId())) { |
||
90 | $linkParameters['sys_language_uid'] = $languageAspect->getId(); |
||
91 | } |
||
92 | $link = (string)$uriBuilder->buildUriFromRoute($moduleName, $linkParameters); |
||
93 | $icon = $iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render(); |
||
94 | $title = $this->getLabel('edit_newContentElement'); |
||
95 | $output[] = '<a class="' . |
||
96 | $classes . |
||
97 | '" href="' . |
||
98 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
99 | '" title="' . |
||
100 | $title . |
||
101 | '">'; |
||
102 | $output[] = ' ' . $icon; |
||
103 | $output[] = '</a>'; |
||
104 | } |
||
105 | |||
106 | // Move Page |
||
107 | if ($perms & Permission::PAGE_EDIT) { |
||
108 | $link = (string)$uriBuilder->buildUriFromRoute( |
||
109 | 'move_element', |
||
110 | [ |
||
111 | 'table' => 'pages', |
||
112 | 'uid' => $id, |
||
113 | 'returnUrl' => $returnUrl, |
||
114 | ] |
||
115 | ); |
||
116 | $icon = $iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL)->render(); |
||
117 | $title = $this->getLabel('edit_move_page'); |
||
118 | $output[] = '<a class="' . |
||
119 | $classes . |
||
120 | '" href="' . |
||
121 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
122 | '" title="' . |
||
123 | $title . |
||
124 | '">'; |
||
125 | $output[] = ' ' . $icon; |
||
126 | $output[] = '</a>'; |
||
127 | } |
||
128 | |||
129 | // New Page |
||
130 | if ($perms & Permission::PAGE_NEW) { |
||
131 | $link = (string)$uriBuilder->buildUriFromRoute( |
||
132 | 'db_new', |
||
133 | [ |
||
134 | 'id' => $id, |
||
135 | 'pagesOnly' => 1, |
||
136 | 'returnUrl' => $returnUrl, |
||
137 | ] |
||
138 | ); |
||
139 | $icon = $iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render(); |
||
140 | $title = $this->getLabel('edit_newPage'); |
||
141 | $output[] = '<a class="' . |
||
142 | $classes . |
||
143 | '" href="' . |
||
144 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
145 | '" title="' . |
||
146 | $title . |
||
147 | '">'; |
||
148 | $output[] = ' ' . $icon; |
||
149 | $output[] = '</a>'; |
||
150 | } |
||
151 | |||
152 | // Edit Page |
||
153 | if ($perms & Permission::PAGE_EDIT) { |
||
154 | $link = (string)$uriBuilder->buildUriFromRoute( |
||
155 | 'record_edit', |
||
156 | [ |
||
157 | 'edit[pages][' . $id . ']' => 'edit', |
||
158 | 'noView' => 1, |
||
159 | 'returnUrl' => $returnUrl, |
||
160 | ] |
||
161 | ); |
||
162 | $icon = $iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render(); |
||
163 | $title = $this->getLabel('edit_editPageProperties'); |
||
164 | $output[] = '<a class="' . |
||
165 | $classes . |
||
166 | '" href="' . |
||
167 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
168 | '" title="' . |
||
169 | $title . |
||
170 | '">'; |
||
171 | $output[] = ' ' . $icon; |
||
172 | $output[] = '</a>'; |
||
173 | } |
||
174 | |||
175 | // Edit Page Overlay |
||
176 | if ($perms & Permission::PAGE_EDIT && $languageAspect->getId() > 0 && $langAllowed) { |
||
177 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
178 | ->getQueryBuilderForTable('pages'); |
||
179 | $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class)); |
||
180 | $row = $queryBuilder |
||
181 | ->select('uid', 'pid', 't3ver_state') |
||
182 | ->from('pages') |
||
183 | ->where( |
||
184 | $queryBuilder->expr()->eq( |
||
185 | $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'], |
||
186 | $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT) |
||
187 | ), |
||
188 | $queryBuilder->expr()->eq( |
||
189 | $GLOBALS['TCA']['pages']['ctrl']['languageField'], |
||
190 | $queryBuilder->createNamedParameter($languageAspect->getId(), \PDO::PARAM_INT) |
||
191 | ) |
||
192 | ) |
||
193 | ->setMaxResults(1) |
||
194 | ->execute() |
||
195 | ->fetch(); |
||
196 | $tsfe->sys_page->versionOL('pages', $row); |
||
197 | if (is_array($row)) { |
||
198 | $link = (string)$uriBuilder->buildUriFromRoute( |
||
199 | 'record_edit', |
||
200 | [ |
||
201 | 'edit[pages][' . $row['uid'] . ']' => 'edit', |
||
202 | 'noView' => 1, |
||
203 | 'returnUrl' => $returnUrl, |
||
204 | ] |
||
205 | ); |
||
206 | $icon = $iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL) |
||
207 | ->render(); |
||
208 | $title = $this->getLabel('edit_editPageOverlay'); |
||
209 | $output[] = '<a class="' . |
||
210 | $classes . |
||
211 | '" href="' . |
||
212 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
213 | '" title="' . |
||
214 | $title . |
||
215 | '">'; |
||
216 | $output[] = ' ' . $icon; |
||
217 | $output[] = '</a>'; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | // Open list view |
||
222 | if ($this->getBackendUser()->check('modules', 'web_list')) { |
||
223 | $link = (string)$uriBuilder->buildUriFromRoute( |
||
224 | 'web_list', |
||
225 | [ |
||
226 | 'id' => $id, |
||
227 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), |
||
228 | ] |
||
229 | ); |
||
230 | $icon = $iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render(); |
||
231 | $title = $this->getLabel('edit_db_list'); |
||
232 | $output[] = '<a class="' . |
||
233 | $classes . |
||
234 | '" href="' . |
||
235 | htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
||
236 | '" title="' . |
||
237 | $title . |
||
238 | '">'; |
||
239 | $output[] = ' ' . $icon; |
||
240 | $output[] = '</a>'; |
||
241 | } |
||
242 | |||
243 | $output[] = ' </div>'; |
||
244 | $output[] = '</div>'; |
||
245 | return implode('', $output); |
||
246 | } |
||
283 |