Custom scopes
Scopes give access to groups of actions. A scope implements
\TYPO3\CMS\Core\Scope\ScopeInterface. Register it with its identifier
with the Symfony attribute #[AsTaggedItem]. The method
allowedForUser() decides if a backend user can get the scope. TYPO3
also calls it for each request. If it returns false, the app loses the
scope for this request.
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use TYPO3\CMS\Core\Scope\ScopeInterface;
use TYPO3\CMS\Core\Scope\ScopeUser;
#[AsTaggedItem(index: 'my-extension:news:read')]
final class NewsReadScope implements ScopeInterface
{
public function getName(): string
{
return 'Read access to news';
}
public function getDescription(): string
{
return 'Read news records.';
}
public function getIcon(): string
{
return 'content-news';
}
public function allowedForUser(ScopeUser $user): bool
{
return true;
}
}EXT:my_extension/Classes/Scope/NewsReadScope.php
php
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use TYPO3\CMS\Core\Scope\ScopeInterface;
use TYPO3\CMS\Core\Scope\ScopeUser;
#[AsTaggedItem(index: 'my-extension:news:read')]
final class NewsReadScope implements ScopeInterface
{
public function getName(): string
{
return 'Read access to news';
}
public function getDescription(): string
{
return 'Read news records.';
}
public function getIcon(): string
{
return 'content-news';
}
public function allowedForUser(ScopeUser $user): bool
{
return true;
}
}
The name, description and icon are shown in the app record and on the OAuth consent screen.