Skip to content

Commit 1487002

Browse files
authored
Merge branch 'main' into feature/recordTitleProvider
2 parents 9b6d337 + d4257fd commit 1487002

22 files changed

+178
-266
lines changed

Build/Scripts/runTests.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ Options:
139139
- composer: "composer" with all remaining arguments dispatched.
140140
- composerNormalize: "composer normalize"
141141
- composerUpdate: "composer update", handy if host has no PHP
142-
- composerUpdateRector: "composer update", for rector subdirectory
143142
- composerValidate: "composer validate"
144143
- functional: PHP functional tests
145144
- lint: PHP linting
@@ -454,18 +453,6 @@ case ${TEST_SUITE} in
454453
cp ${ROOT_DIR}/composer.json ${ROOT_DIR}/composer.json.testing
455454
mv ${ROOT_DIR}/composer.json.orig ${ROOT_DIR}/composer.json
456455
;;
457-
composerUpdateRector)
458-
rm -rf Build/rector/.Build/bin/ Build/rector/.Build/vendor Build/rector/composer.lock
459-
cp ${ROOT_DIR}/Build/rector/composer.json ${ROOT_DIR}/Build/rector/composer.json.orig
460-
if [ -f "${ROOT_DIR}/Build/rector/composer.json.testing" ]; then
461-
cp ${ROOT_DIR}/Build/rector/composer.json ${ROOT_DIR}/Build/rector/composer.json.orig
462-
fi
463-
COMMAND=(composer require --working-dir=${ROOT_DIR}/Build/rector --no-ansi --no-interaction --no-progress)
464-
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-install-${SUFFIX} -e COMPOSER_CACHE_DIR=.Build/.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} "${COMMAND[@]}"
465-
SUITE_EXIT_CODE=$?
466-
cp ${ROOT_DIR}/Build/rector/composer.json ${ROOT_DIR}/Build/rector/composer.json.testing
467-
mv ${ROOT_DIR}/Build/rector/composer.json.orig ${ROOT_DIR}/Build/rector/composer.json
468-
;;
469456
composerValidate)
470457
COMMAND=(composer validate "$@")
471458
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.Build/.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} "${COMMAND[@]}"
@@ -524,9 +511,9 @@ case ${TEST_SUITE} in
524511
;;
525512
rector)
526513
if [ "${CGLCHECK_DRY_RUN}" -eq 1 ]; then
527-
COMMAND=(php -dxdebug.mode=off Build/rector/.Build/bin/rector -n --config=Build/rector/rector.php --clear-cache "$@")
514+
COMMAND=(php -dxdebug.mode=off .Build/bin/rector -n --config=Build/rector/rector.php --clear-cache "$@")
528515
else
529-
COMMAND=(php -dxdebug.mode=off Build/rector/.Build/bin/rector --config=Build/rector/rector.php --clear-cache "$@")
516+
COMMAND=(php -dxdebug.mode=off .Build/bin/rector --config=Build/rector/rector.php --clear-cache "$@")
530517
fi
531518
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name rector-${SUFFIX} -e COMPOSER_CACHE_DIR=.Build/.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} "${COMMAND[@]}"
532519
SUITE_EXIT_CODE=$?

Build/rector/composer.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

Classes/Controller/AbstractController.php

Lines changed: 0 additions & 97 deletions
This file was deleted.

Classes/Controller/BackendController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(
6464

6565
public function addPopulateButton(ButtonBar $buttonBar): void
6666
{
67-
$populateButton = $buttonBar->makeLinkButton()
67+
$populateButton = $this->componentFactory->createLinkButton()
6868
->setHref($this->uriBuilder->reset()->uriFor('populate'))
6969
->setTitle('Create example data')
7070
->setShowLabelText(true)
@@ -235,13 +235,13 @@ private function modifyDocHeaderComponent(ModuleTemplate $view, string &$context
235235

236236
$metaInformation = $this->getMetaInformation();
237237
if (is_array($metaInformation)) {
238-
$view->getDocHeaderComponent()->setMetaInformation($metaInformation);
238+
$view->getDocHeaderComponent()->setPageBreadcrumb($metaInformation);
239239
}
240240
}
241241

242242
private function addReloadButton(ButtonBar $buttonBar): void
243243
{
244-
$reloadButton = $buttonBar->makeLinkButton()
244+
$reloadButton = $this->componentFactory->createLinkButton()
245245
->setHref($this->request->getAttribute('normalizedParams')->getRequestUri())
246246
->setTitle($this->getLanguageService()->sL('core.core:labels.reload'))
247247
->setIcon($this->iconFactory->getIcon('actions-refresh', IconSize::SMALL));
@@ -250,7 +250,7 @@ private function addReloadButton(ButtonBar $buttonBar): void
250250

251251
private function addShortCutButton(ButtonBar $buttonBar): void
252252
{
253-
$shortcutButton = $buttonBar->makeShortcutButton()
253+
$shortcutButton = $this->componentFactory->createShortcutButton()
254254
->setRouteIdentifier('blog_example')
255255
->setDisplayName($this->getLanguageService()->sL('blog_example.messages:administration.menu.index'));
256256
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
@@ -280,12 +280,12 @@ private function buildMenu(ModuleTemplate $view, string &$context): Menu
280280
//$menu = $this->componentFactory->createMenu();
281281
//$menu->setIdentifier('viewSelector')->setLabel('View');
282282

283-
$menu = $view->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
283+
$menu = $this->componentFactory->createMenu();
284284
$menu->setIdentifier('BlogExampleModuleMenu')->setLabel('View');
285285

286286
foreach ($menuItems as $menuItemConfig) {
287287
$isActive = $this->request->getControllerActionName() === $menuItemConfig['action'];
288-
$menuItem = $menu->makeMenuItem()
288+
$menuItem = $this->componentFactory->createMenuItem()
289289
->setTitle($menuItemConfig['label'])
290290
->setHref($this->uriBuilder->reset()->uriFor(
291291
$menuItemConfig['action'],

Classes/Controller/BlogController.php

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
2828
use TYPO3\CMS\Extbase\Attribute\IgnoreValidation;
2929
use TYPO3\CMS\Extbase\Attribute\Validate;
30+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
3031
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
32+
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
3133

3234
/**
3335
* The blog controller for the BlogExample extension
3436
*/
35-
class BlogController extends AbstractController
37+
class BlogController extends ActionController
3638
{
3739
/**
3840
* BlogController constructor.
@@ -77,9 +79,10 @@ public function helloWorldAction(): ResponseInterface
7779
/**
7880
* Displays a form for creating a new blog
7981
*/
80-
#[IgnoreValidation(['value' => 'newBlog'])]
81-
public function newAction(?Blog $newBlog = null): ResponseInterface
82-
{
82+
public function newAction(
83+
#[IgnoreValidation]
84+
?Blog $newBlog = null,
85+
): ResponseInterface {
8386
$this->view->assignMultiple([
8487
'newBlog' => $newBlog,
8588
'administrators' => $this->administratorRepository->findAll(),
@@ -93,9 +96,10 @@ public function newAction(?Blog $newBlog = null): ResponseInterface
9396
* $blog is a fresh Blog object which has not yet been added to the
9497
* repository
9598
*/
96-
#[Validate(['param' => 'newBlog', 'validator' => BlogValidator::class])]
97-
public function createAction(Blog $newBlog): ResponseInterface
98-
{
99+
public function createAction(
100+
#[Validate(validator: BlogValidator::class)]
101+
Blog $newBlog,
102+
): ResponseInterface {
99103
$this->checkBlogAdminAccess();
100104
$this->blogRepository->add($newBlog);
101105
$this->addFlashMessage('created');
@@ -109,9 +113,10 @@ public function createAction(Blog $newBlog): ResponseInterface
109113
* modifications if the edit form has been submitted, contained errors and
110114
* therefore ended up in this action again.
111115
*/
112-
#[IgnoreValidation(['value' => 'blog'])]
113-
public function editAction(Blog $blog): ResponseInterface
114-
{
116+
public function editAction(
117+
#[IgnoreValidation]
118+
Blog $blog,
119+
): ResponseInterface {
115120
$this->view->assignMultiple([
116121
'blog' => $blog,
117122
'administrators' => $this->administratorRepository->findAll(),
@@ -127,9 +132,10 @@ public function editAction(Blog $blog): ResponseInterface
127132
*
128133
* @throws NoBlogAdminAccessException
129134
*/
130-
#[Validate(['param' => 'blog', 'validator' => BlogValidator::class])]
131-
public function updateAction(Blog $blog): ResponseInterface
132-
{
135+
public function updateAction(
136+
#[Validate(validator: BlogValidator::class)]
137+
Blog $blog,
138+
): ResponseInterface {
133139
$this->checkBlogAdminAccess();
134140
$this->blogRepository->update($blog);
135141
$this->addFlashMessage('updated');
@@ -180,4 +186,34 @@ public function showBlogAjaxAction(Blog $blog): ResponseInterface
180186
$jsonOutput = json_encode($blog);
181187
return $this->jsonResponse($jsonOutput);
182188
}
189+
/**
190+
* Override getErrorFlashMessage to present
191+
* nice flash error messages.
192+
*/
193+
protected function getErrorFlashMessage(): string
194+
{
195+
$defaultFlashMessage = parent::getErrorFlashMessage();
196+
$locallangKey = sprintf(
197+
'error.%s.%s',
198+
$this->request->getControllerName(),
199+
$this->actionMethodName,
200+
);
201+
return LocalizationUtility::translate($locallangKey, 'BlogExample') ?? $defaultFlashMessage;
202+
}
203+
204+
protected function hasBlogAdminAccess(): bool
205+
{
206+
// TODO access protection
207+
return true;
208+
}
209+
210+
/**
211+
* @throws NoBlogAdminAccessException
212+
*/
213+
protected function checkBlogAdminAccess(): void
214+
{
215+
if (!$this->hasBlogAdminAccess()) {
216+
throw new NoBlogAdminAccessException();
217+
}
218+
}
183219
}

Classes/Controller/CommentController.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use T3docs\BlogExample\Exception\NoBlogAdminAccessException;
1313
use T3docs\BlogExample\Property\TypeConverters\HiddenCommentConverter;
1414
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
15+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
1516
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
17+
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
1618

1719
/*
1820
* This file is part of the TYPO3 CMS project.
@@ -30,7 +32,7 @@
3032
/**
3133
* The comment controller for the BlogExample extension
3234
*/
33-
class CommentController extends AbstractController
35+
class CommentController extends ActionController
3436
{
3537
/**
3638
* CommentController constructor.
@@ -109,4 +111,34 @@ public function deleteAllAction(Post $post): ResponseInterface
109111
['post' => $post, 'blog' => $post->getBlog()],
110112
);
111113
}
114+
/**
115+
* Override getErrorFlashMessage to present
116+
* nice flash error messages.
117+
*/
118+
protected function getErrorFlashMessage(): string
119+
{
120+
$defaultFlashMessage = parent::getErrorFlashMessage();
121+
$locallangKey = sprintf(
122+
'error.%s.%s',
123+
$this->request->getControllerName(),
124+
$this->actionMethodName,
125+
);
126+
return LocalizationUtility::translate($locallangKey, 'BlogExample') ?? $defaultFlashMessage;
127+
}
128+
129+
protected function hasBlogAdminAccess(): bool
130+
{
131+
// TODO access protection
132+
return true;
133+
}
134+
135+
/**
136+
* @throws NoBlogAdminAccessException
137+
*/
138+
protected function checkBlogAdminAccess(): void
139+
{
140+
if (!$this->hasBlogAdminAccess()) {
141+
throw new NoBlogAdminAccessException();
142+
}
143+
}
112144
}

0 commit comments

Comments
 (0)