Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 0 additions & 97 deletions Classes/Controller/AbstractController.php

This file was deleted.

34 changes: 33 additions & 1 deletion Classes/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Attribute\IgnoreValidation;
use TYPO3\CMS\Extbase\Attribute\Validate;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* The blog controller for the BlogExample extension
*/
class BlogController extends AbstractController
class BlogController extends ActionController
{
/**
* BlogController constructor.
Expand Down Expand Up @@ -180,4 +182,34 @@ public function showBlogAjaxAction(Blog $blog): ResponseInterface
$jsonOutput = json_encode($blog);
return $this->jsonResponse($jsonOutput);
}
/**
* Override getErrorFlashMessage to present
* nice flash error messages.
*/
protected function getErrorFlashMessage(): string
{
$defaultFlashMessage = parent::getErrorFlashMessage();
$locallangKey = sprintf(
'error.%s.%s',
$this->request->getControllerName(),
$this->actionMethodName,
);
return LocalizationUtility::translate($locallangKey, 'BlogExample') ?? $defaultFlashMessage;
}

protected function hasBlogAdminAccess(): bool
{
// TODO access protection
return true;
}

/**
* @throws NoBlogAdminAccessException
*/
protected function checkBlogAdminAccess(): void
{
if (!$this->hasBlogAdminAccess()) {
throw new NoBlogAdminAccessException();
}
}
}
34 changes: 33 additions & 1 deletion Classes/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use T3docs\BlogExample\Exception\NoBlogAdminAccessException;
use T3docs\BlogExample\Property\TypeConverters\HiddenCommentConverter;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/*
* This file is part of the TYPO3 CMS project.
Expand All @@ -30,7 +32,7 @@
/**
* The comment controller for the BlogExample extension
*/
class CommentController extends AbstractController
class CommentController extends ActionController
{
/**
* CommentController constructor.
Expand Down Expand Up @@ -109,4 +111,34 @@ public function deleteAllAction(Post $post): ResponseInterface
['post' => $post, 'blog' => $post->getBlog()],
);
}
/**
* Override getErrorFlashMessage to present
* nice flash error messages.
*/
protected function getErrorFlashMessage(): string
{
$defaultFlashMessage = parent::getErrorFlashMessage();
$locallangKey = sprintf(
'error.%s.%s',
$this->request->getControllerName(),
$this->actionMethodName,
);
return LocalizationUtility::translate($locallangKey, 'BlogExample') ?? $defaultFlashMessage;
}

protected function hasBlogAdminAccess(): bool
{
// TODO access protection
return true;
}

/**
* @throws NoBlogAdminAccessException
*/
protected function checkBlogAdminAccess(): void
{
if (!$this->hasBlogAdminAccess()) {
throw new NoBlogAdminAccessException();
}
}
}
34 changes: 33 additions & 1 deletion Classes/Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Attribute\IgnoreValidation;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Property\Exception;
use TYPO3\CMS\Extbase\Property\PropertyMapper;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/*
* This file is part of the TYPO3 CMS project.
Expand All @@ -39,7 +41,7 @@
/**
* The post controller for the BlogExample extension
*/
class PostController extends AbstractController
class PostController extends ActionController
{
/**
* PostController constructor.
Expand Down Expand Up @@ -235,4 +237,34 @@ public function deleteAction(
$this->addFlashMessage('The post has been deleted.', 'Deleted', ContextualFeedbackSeverity::INFO);
return $this->redirect('index', null, null, ['blog' => $blog]);
}
/**
* Override getErrorFlashMessage to present
* nice flash error messages.
*/
protected function getErrorFlashMessage(): string
{
$defaultFlashMessage = parent::getErrorFlashMessage();
$locallangKey = sprintf(
'error.%s.%s',
$this->request->getControllerName(),
$this->actionMethodName,
);
return LocalizationUtility::translate($locallangKey, 'BlogExample') ?? $defaultFlashMessage;
}

protected function hasBlogAdminAccess(): bool
{
// TODO access protection
return true;
}

/**
* @throws NoBlogAdminAccessException
*/
protected function checkBlogAdminAccess(): void
{
if (!$this->hasBlogAdminAccess()) {
throw new NoBlogAdminAccessException();
}
}
}
Loading