Complex classes like AdministrationController 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 AdministrationController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class AdministrationController extends AbstractController |
||
39 | { |
||
40 | const LANG_FILE = 'LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:'; |
||
41 | |||
42 | /** |
||
43 | * Backend Template Container |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class; |
||
48 | |||
49 | /** |
||
50 | * CustomNotificationLogRepository |
||
51 | * |
||
52 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository |
||
53 | */ |
||
54 | protected $customNotificationLogRepository; |
||
55 | |||
56 | /** |
||
57 | * ExportService |
||
58 | * |
||
59 | * @var \DERHANSEN\SfEventMgt\Service\ExportService |
||
60 | */ |
||
61 | protected $exportService; |
||
62 | |||
63 | /** |
||
64 | * SettingsService |
||
65 | * |
||
66 | * @var \DERHANSEN\SfEventMgt\Service\SettingsService |
||
67 | */ |
||
68 | protected $settingsService; |
||
69 | |||
70 | /** |
||
71 | * Backend User Session Service |
||
72 | * |
||
73 | * @var \DERHANSEN\SfEventMgt\Service\BeUserSessionService |
||
74 | */ |
||
75 | protected $beUserSessionService; |
||
76 | |||
77 | /** |
||
78 | * @var \DERHANSEN\SfEventMgt\Service\MaintenanceService |
||
79 | */ |
||
80 | protected $maintenanceService; |
||
81 | |||
82 | /** |
||
83 | * The current page uid |
||
84 | * |
||
85 | * @var int |
||
86 | */ |
||
87 | protected $pid = 0; |
||
88 | |||
89 | /** |
||
90 | * BackendTemplateContainer |
||
91 | 2 | * |
|
92 | * @var BackendTemplateView |
||
93 | 2 | */ |
|
94 | 2 | protected $view; |
|
95 | |||
96 | /** |
||
97 | * @var IconFactory |
||
98 | */ |
||
99 | protected $iconFactory; |
||
100 | |||
101 | 4 | /** |
|
102 | * DI for $customNotificationLogRepository |
||
103 | 4 | * |
|
104 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository |
|
105 | 2 | */ |
|
106 | 4 | public function injectCustomNotificationLogRepository( |
|
107 | 4 | \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository |
|
108 | 4 | ) { |
|
109 | 4 | $this->customNotificationLogRepository = $customNotificationLogRepository; |
|
110 | 4 | } |
|
111 | 4 | ||
112 | 4 | /** |
|
113 | 4 | * DI for $exportService |
|
114 | 4 | * |
|
115 | 4 | * @param Service\ExportService $exportService |
|
116 | 4 | */ |
|
117 | 4 | public function injectExportService(\DERHANSEN\SfEventMgt\Service\ExportService $exportService) |
|
118 | 4 | { |
|
119 | 4 | $this->exportService = $exportService; |
|
120 | 4 | } |
|
121 | |||
122 | /** |
||
123 | * DI for $settingsService |
||
124 | * |
||
125 | * @param Service\SettingsService $settingsService |
||
126 | */ |
||
127 | public function injectSettingsService(\DERHANSEN\SfEventMgt\Service\SettingsService $settingsService) |
||
128 | { |
||
129 | $this->settingsService = $settingsService; |
||
130 | 8 | } |
|
131 | |||
132 | /** |
||
133 | 8 | * DI for $beUserSessionService |
|
134 | * |
||
135 | 8 | * @param Service\BeUserSessionService $beUserSessionService |
|
136 | 6 | */ |
|
137 | 6 | public function injectBeUserSessionService(\DERHANSEN\SfEventMgt\Service\BeUserSessionService $beUserSessionService) |
|
138 | 8 | { |
|
139 | $this->beUserSessionService = $beUserSessionService; |
||
140 | 8 | } |
|
141 | 4 | ||
142 | 4 | /** |
|
143 | * DI for $iconFactory |
||
144 | 8 | * |
|
145 | 2 | * @param IconFactory $iconFactory |
|
146 | 2 | */ |
|
147 | 2 | public function injectIconFactory(IconFactory $iconFactory) |
|
148 | 2 | { |
|
149 | $this->iconFactory = $iconFactory; |
||
150 | 8 | } |
|
151 | 8 | ||
152 | 8 | /** |
|
153 | 8 | * @param Service\MaintenanceService $maintenanceService |
|
154 | */ |
||
155 | public function injectMaintenanceService(\DERHANSEN\SfEventMgt\Service\MaintenanceService $maintenanceService) |
||
156 | { |
||
157 | $this->maintenanceService = $maintenanceService; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Set up the doc header properly here |
||
162 | 2 | * |
|
163 | * @param ViewInterface $view |
||
164 | 2 | */ |
|
165 | 2 | protected function initializeView(ViewInterface $view) |
|
166 | { |
||
167 | /** @var BackendTemplateView $view */ |
||
168 | parent::initializeView($view); |
||
169 | if ($this->actionMethodName === 'listAction' |
||
170 | || $this->actionMethodName === 'indexNotifyAction' |
||
171 | || $this->actionMethodName === 'settingsErrorAction' |
||
172 | ) { |
||
173 | 2 | $this->registerDocHeaderButtons(); |
|
174 | |||
175 | 2 | $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer(); |
|
176 | 2 | $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker'); |
|
177 | 2 | ||
178 | $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? |
||
179 | ['MM-DD-YYYY', 'HH:mm MM-DD-YYYY'] : |
||
180 | ['DD-MM-YYYY', 'HH:mm DD-MM-YYYY']; |
||
181 | $pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat); |
||
182 | |||
183 | $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue()); |
||
184 | if ($view instanceof BackendTemplateView) { |
||
185 | $view->getModuleTemplate()->getPageRenderer()->addCssFile( |
||
186 | 2 | 'EXT:sf_event_mgt/Resources/Public/Css/administration.css' |
|
187 | ); |
||
188 | 2 | } |
|
189 | 2 | } |
|
190 | 2 | } |
|
191 | 2 | ||
192 | 2 | /** |
|
193 | 2 | * Register docHeaderButtons |
|
194 | 2 | */ |
|
195 | 2 | protected function registerDocHeaderButtons() |
|
196 | { |
||
197 | $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar(); |
||
198 | |||
199 | $uriBuilder = $this->objectManager->get(ExtbaseUriBuilder::class); |
||
|
|||
200 | $uriBuilder->setRequest($this->request); |
||
201 | |||
202 | if ($this->request->getControllerActionName() === 'list') { |
||
203 | $buttons = [ |
||
204 | [ |
||
205 | 2 | 'label' => 'administration.newEvent', |
|
206 | 'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_event'), |
||
207 | 2 | 'icon' => 'ext-sfeventmgt-event', |
|
208 | 2 | 'group' => 1 |
|
209 | 2 | ], |
|
210 | 2 | [ |
|
211 | 2 | 'label' => 'administration.newLocation', |
|
212 | 'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_location'), |
||
213 | 2 | 'icon' => 'ext-sfeventmgt-location', |
|
214 | 2 | 'group' => 1 |
|
215 | 2 | ], |
|
216 | [ |
||
217 | 'label' => 'administration.newOrganisator', |
||
218 | 'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_organisator'), |
||
219 | 'icon' => 'ext-sfeventmgt-organisator', |
||
220 | 'group' => 1 |
||
221 | ], |
||
222 | [ |
||
223 | 'label' => 'administration.newSpeaker', |
||
224 | 'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_speaker'), |
||
225 | 'icon' => 'ext-sfeventmgt-speaker', |
||
226 | 'group' => 1 |
||
227 | ], |
||
228 | [ |
||
229 | 'label' => 'administration.handleExpiredRegistrations', |
||
230 | 'link' => $uriBuilder->reset()->setRequest($this->request) |
||
231 | ->uriFor('handleExpiredRegistrations', [], 'Administration'), |
||
232 | 'icon' => 'ext-sfeventmgt-action-handle-expired', |
||
233 | 'group' => 2, |
||
234 | ] |
||
235 | ]; |
||
236 | foreach ($buttons as $key => $tableConfiguration) { |
||
237 | $title = $this->getLanguageService()->sL(self::LANG_FILE . $tableConfiguration['label']); |
||
238 | $icon = $this->iconFactory->getIcon($tableConfiguration['icon'], Icon::SIZE_SMALL); |
||
239 | $viewButton = $buttonBar->makeLinkButton() |
||
240 | ->setHref($tableConfiguration['link']) |
||
241 | ->setDataAttributes([ |
||
242 | 'toggle' => 'tooltip', |
||
243 | 'placement' => 'bottom', |
||
244 | 'title' => $title |
||
245 | ]) |
||
246 | ->setTitle($title) |
||
247 | ->setIcon($icon); |
||
248 | $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, $tableConfiguration['group']); |
||
249 | } |
||
250 | } |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Returns the create new record URL for the given table |
||
255 | * |
||
256 | * @param $table |
||
257 | * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException |
||
258 | * @return string |
||
259 | */ |
||
260 | private function getCreateNewRecordUri($table): string |
||
261 | { |
||
262 | $pid = $this->pid; |
||
263 | $tsConfig = BackendUtility::getPagesTSconfig(0); |
||
264 | if ($pid === 0 && isset($tsConfig['defaultPid.']) |
||
265 | && is_array($tsConfig['defaultPid.']) |
||
266 | && isset($tsConfig['defaultPid.'][$table]) |
||
267 | ) { |
||
268 | $pid = (int)$tsConfig['defaultPid.'][$table]; |
||
269 | } |
||
270 | |||
271 | $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
||
272 | |||
273 | return $uriBuilder->buildUriFromRoute('record_edit', [ |
||
274 | 'edit[' . $table . '][' . $pid . ']' => 'new', |
||
275 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
276 | ]); |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * Initialize action |
||
281 | */ |
||
282 | public function initializeAction() |
||
283 | { |
||
284 | $this->pid = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id'); |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Set date format for fields startDate and endDate |
||
289 | */ |
||
290 | public function initializeListAction() |
||
310 | |||
311 | /** |
||
312 | * List action for backend module |
||
313 | * |
||
314 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
315 | * @param array $overwriteDemand OverwriteDemand |
||
316 | */ |
||
317 | public function listAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
||
318 | { |
||
319 | /** @var EventDemand $eventDemand */ |
||
320 | $eventDemand = $this->objectManager->get(EventDemand::class); |
||
354 | |||
355 | /** |
||
356 | * Export registrations for a given event |
||
357 | * |
||
358 | * @param int $eventUid Event UID |
||
359 | */ |
||
360 | public function exportAction($eventUid) |
||
370 | |||
371 | /** |
||
372 | * Handles expired registrations |
||
373 | */ |
||
374 | public function handleExpiredRegistrationsAction() |
||
387 | |||
388 | /** |
||
389 | * The index notify action |
||
390 | * |
||
391 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
392 | */ |
||
393 | public function indexNotifyAction(Event $event) |
||
407 | |||
408 | /** |
||
409 | * Returns an array of recipient option for the indexNotify action |
||
410 | * |
||
411 | * @return array|array[] |
||
412 | */ |
||
413 | public function getNotificationRecipients(): array |
||
436 | |||
437 | /** |
||
438 | * Notify action |
||
439 | * |
||
440 | * @param Event $event Event |
||
441 | * @param CustomNotification $customNotification |
||
442 | */ |
||
443 | public function notifyAction(Event $event, CustomNotification $customNotification) |
||
460 | |||
461 | /** |
||
462 | * Checks if the current backend user has access to the PID of the event and if not, enqueue an |
||
463 | * access denied flash message and redirect to list view |
||
464 | * |
||
465 | * @param Event $event |
||
466 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
467 | */ |
||
468 | public function checkEventAccess(Event $event) |
||
480 | |||
481 | /** |
||
482 | * Shows the settings error view |
||
483 | */ |
||
484 | public function settingsErrorAction() |
||
487 | |||
488 | /** |
||
489 | * Suppress default validation messages |
||
490 | * |
||
491 | * @return bool |
||
492 | */ |
||
493 | protected function getErrorFlashMessage() |
||
497 | |||
498 | /** |
||
499 | * Returns the LanguageService |
||
500 | * |
||
501 | * @return LanguageService |
||
502 | */ |
||
503 | protected function getLanguageService(): LanguageService |
||
507 | |||
508 | /** |
||
509 | * Returns an array with possible order directions |
||
510 | * |
||
511 | * @return array |
||
512 | */ |
||
513 | public function getOrderDirections() |
||
520 | |||
521 | /** |
||
522 | * Returns an array with possible orderBy fields |
||
523 | * |
||
524 | * @return array |
||
525 | */ |
||
526 | public function getOrderByFields() |
||
534 | |||
535 | /** |
||
536 | * Returns the Backend User |
||
537 | * @return BackendUserAuthentication |
||
538 | */ |
||
539 | protected function getBackendUser(): BackendUserAuthentication |
||
543 | } |
||
544 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.