Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it work with typo3 10 #237

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use CuyZ\Notiz\Service\LocalizationService;
use ReflectionClass;
use TYPO3\CMS\Backend\Controller\EditDocumentController;
use TYPO3\CMS\Backend\Controller\Event\AfterFormEnginePageInitializedEvent;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Imaging\Icon;
Expand Down Expand Up @@ -60,10 +61,12 @@ public function __construct(DefinitionService $definitionService, IconFactory $i
}

/**
* @param EditDocumentController $controller
* @param AfterFormEnginePageInitializedEvent $controller
*/
public function addButton(EditDocumentController $controller)
public function addButton(AfterFormEnginePageInitializedEvent $event)
{
$controller = $event->getController();

if ($this->definitionService->getValidationResult()->hasErrors()) {
return;
}
Expand Down Expand Up @@ -101,7 +104,8 @@ protected function getNotification(NotificationDefinition $notificationDefinitio
return null;
}

$uid = reset(array_keys($controller->editconf[$tableName]));
$array = array_keys($controller->editconf[$tableName]);
$uid = reset($array);

// We show the button only for existing records being edited.
if ($controller->editconf[$tableName][$uid] !== 'edit') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function getDefinitionErrorTca(): array
'definition_error_message' => [
'config' => [
'type' => 'user',
'userFunc' => self::class . '->getDefinitionErrorMessage',
'renderType' => 'notizDefinitionErrorMessage',
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/Module/AdministrationModuleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function getDefaultControllerName(): string
*/
public function getModuleName(): string
{
return 'NotizNotiz_NotizNotizAdministration';
return 'notiz_NotizNotizAdministration';
}
}
21 changes: 15 additions & 6 deletions Classes/Backend/Module/ManagerModuleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

namespace CuyZ\Notiz\Backend\Module;

use CuyZ\Notiz\Controller\Backend\Manager\ListNotificationTypesController;
use CuyZ\Notiz\Controller\Backend\Manager\Notification\ShowEntityEmailController;
use CuyZ\Notiz\Controller\Backend\Manager\Notification\ShowEntityLogController;
use CuyZ\Notiz\Controller\Backend\Manager\Notification\ShowEntitySlackController;
use CuyZ\Notiz\Service\Traits\ExtendedSelfInstantiateTrait;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

class ManagerModuleHandler extends ModuleHandler
{
Expand All @@ -28,15 +33,15 @@ class ManagerModuleHandler extends ModuleHandler
*/
public function getDefaultControllerName(): string
{
return 'Backend\\Manager\\ListNotificationTypes';
return ListNotificationTypesController::class;
}

/**
* @return string
*/
public function getModuleName(): string
{
return 'NotizNotiz_NotizNotizManager';
return 'notiz_NotizNotizManager';
}

/**
Expand All @@ -45,21 +50,25 @@ public function getModuleName(): string
public function registerEntityNotificationControllers()
{
$controllers = [
'Backend\\Manager\\Notification\\ShowEntityEmail' => [
ShowEntityEmailController::class => [
'show',
'preview',
'previewError',
],
'Backend\\Manager\\Notification\\ShowEntityLog' => [
ShowEntityLogController::class => [
'show',
],
'Backend\\Manager\\Notification\\ShowEntitySlack' => [
ShowEntitySlackController::class => [
'show',
],
];

foreach ($controllers as $controller => $actions) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['Notiz']['modules'][$this->getModuleName()]['controllers'][$controller] = ['actions' => $actions];
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['Notiz']['modules'][$this->getModuleName()]['controllers'][$controller] = [
'actions' => $actions,
'className' => $controller,
'alias' => ExtensionUtility::resolveControllerAliasFromControllerClassName($controller)
];
}
}
}
10 changes: 8 additions & 2 deletions Classes/Backend/Module/ModuleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ abstract class ModuleHandler implements SingletonInterface
public function __construct(DefinitionService $definitionService)
{
$this->definitionService = $definitionService;
$this->uriBuilder = Container::get(UriBuilder::class, $this);
}

/**
Expand All @@ -62,6 +61,9 @@ public static function for(string $module): ModuleHandler
*/
public function getUriBuilder(): UriBuilder
{
if ($this->uriBuilder === null) {
$this->uriBuilder = Container::get(UriBuilder::class, $this);
}
return $this->uriBuilder;
}

Expand All @@ -70,7 +72,11 @@ public function getUriBuilder(): UriBuilder
*/
public function canBeAccessed(): bool
{
return Container::getBackendUser()->modAccess($GLOBALS['TBE_MODULES']['_configuration'][$this->getModuleName()], false);
try {
return Container::getBackendUser()->modAccess($GLOBALS['TBE_MODULES']['_configuration'][$this->getModuleName()]);
} catch (\RuntimeException $exception) {
return false;
}
}

/**
Expand Down
5 changes: 0 additions & 5 deletions Classes/Backend/Module/Uri/UriBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ public function build(): UriInterface
$uri = $this->uriBuilder
->reset()
->setArguments([
/*
* @deprecated `M` arguments must be removed when TYPO3 v8 is
* not supported anymore.
*/
'M' => $module,
'route' => $module,
])
->uriFor(
Expand Down
6 changes: 4 additions & 2 deletions Classes/Backend/ToolBarItems/NotificationsToolbarItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -135,13 +136,14 @@ public function getDropDown(): string
* Action called periodically by Ajax (used to refresh the toolbar).
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function renderMenuAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
public function renderMenuAction(ServerRequestInterface $request): ResponseInterface
{
$this->fullMenu = true;

$response = new Response();

$response->getBody()->write($this->getDropDown());

return $response->withHeader('Content-Type', 'text/html; charset=utf-8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
use CuyZ\Notiz\Controller\Backend\Menu;
use CuyZ\Notiz\Core\Channel\Payload;
use CuyZ\Notiz\Core\Definition\Tree\Notification\NotificationDefinition;
use CuyZ\Notiz\Core\Event\Event;
use CuyZ\Notiz\Core\Event\Service\EventFactory;
use CuyZ\Notiz\Core\Event\Support\ProvidesExampleProperties;
use CuyZ\Notiz\Core\Notification\Notification;
use CuyZ\Notiz\Core\Property\Factory\PropertyContainer;
use CuyZ\Notiz\Core\Property\Factory\PropertyFactory;
use CuyZ\Notiz\Core\Property\Factory\PropertyFillingEvent;
use TYPO3\CMS\Core\EventDispatcher\ListenerProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;

abstract class ShowNotificationController extends ManagerController
Expand All @@ -41,11 +41,6 @@ abstract class ShowNotificationController extends ManagerController
*/
protected $notification;

/**
* @var EventFactory
*/
protected $eventFactory;

/**
* @param ViewInterface $view
*/
Expand Down Expand Up @@ -118,37 +113,30 @@ protected function fetchNotification()
*/
protected function getPreviewPayload(): Payload
{
$fakeEvent = $this->eventFactory->create($this->notification->getEventDefinition(), $this->notification);
$fakeEvent = EventFactory::create($this->notification->getEventDefinition(), $this->notification);

if ($fakeEvent instanceof ProvidesExampleProperties) {
$this->signalSlotDispatcher->connect(
PropertyFactory::class,
PropertyFactory::SIGNAL_PROPERTY_FILLING,
function (PropertyContainer $container, Event $event) use ($fakeEvent) {
if ($event !== $fakeEvent) {
return;
}

$exampleProperties = $fakeEvent->getExampleProperties();

foreach ($container->getEntries() as $property) {
if (isset($exampleProperties[$property->getName()])) {
$property->setValue($exampleProperties[$property->getName()]);
}
}
}
);
GeneralUtility::makeInstance(ListenerProvider::class)
->addListener(PropertyFillingEvent::class, \get_class($this), 'onPropertyFilling');
}

return new Payload($this->notification, $this->notificationDefinition, $fakeEvent);
}

/**
* @param EventFactory $eventFactory
*/
public function injectEventFactory(EventFactory $eventFactory)
public function onPropertyFilling(PropertyFillingEvent $propertyFillingEvent)
{
$this->eventFactory = $eventFactory;
$event = $propertyFillingEvent->getEvent();
$container = $propertyFillingEvent->getPropertyContainer();

if ($event instanceof ProvidesExampleProperties) {
$exampleProperties = $event->getExampleProperties();
}

foreach ($container->getEntries() as $property) {
if (isset($exampleProperties[$property->getName()])) {
$property->setValue($exampleProperties[$property->getName()]);
}
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Core/Channel/AbstractChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public static function getSettingsClassName(): string
$reflectionService = Container::get(ReflectionService::class);

$settingsProperty = $reflectionService->getClassSchema(static::class)->getProperty('settings');
$settingsClassName = $settingsProperty['type'];

return $settingsClassName;
return $settingsProperty->getType();
}
}
35 changes: 13 additions & 22 deletions Classes/Core/Definition/Builder/DefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
namespace CuyZ\Notiz\Core\Definition\Builder;

use CuyZ\Notiz\Core\Definition\Builder\Component\DefinitionComponents;
use CuyZ\Notiz\Core\Definition\Builder\Event\DefinitionBuilderBuiltEvent;
use CuyZ\Notiz\Core\Definition\Builder\Event\DefinitionBuilderManageComponentEvent;
use CuyZ\Notiz\Core\Definition\Tree\Definition;
use CuyZ\Notiz\Core\Support\NotizConstants;
use CuyZ\Notiz\Service\CacheService;
use CuyZ\Notiz\Service\Traits\ExtendedSelfInstantiateTrait;
use CuyZ\Notiz\Validation\Validator\DefinitionValidator;
use Psr\EventDispatcher\EventDispatcherInterface;
use Romm\ConfigurationObject\ConfigurationObjectFactory;
use Romm\ConfigurationObject\ConfigurationObjectInstance;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;

/**
* This class is responsible for building a whole PHP definition object that can
Expand Down Expand Up @@ -62,7 +64,7 @@
*
* ---
*
* Register new components
* Register new components TODO update docs
* -----------------------
*
* To register new components in your own API, you first need to connect a class
Expand Down Expand Up @@ -105,9 +107,6 @@ class DefinitionBuilder implements SingletonInterface
{
use ExtendedSelfInstantiateTrait;

const COMPONENTS_SIGNAL = 'manageDefinitionComponents';
const DEFINITION_BUILT_SIGNAL = 'definitionBuilt';

/**
* @var DefinitionComponents
*/
Expand All @@ -124,20 +123,20 @@ class DefinitionBuilder implements SingletonInterface
protected $cacheService;

/**
* @var Dispatcher
* @var EventDispatcherInterface
*/
protected $dispatcher;
protected $eventDispatcher;

/**
* @param DefinitionComponents $components
* @param CacheService $cacheService
* @param Dispatcher $dispatcher
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(DefinitionComponents $components, CacheService $cacheService, Dispatcher $dispatcher)
public function __construct(DefinitionComponents $components, CacheService $cacheService, EventDispatcherInterface $eventDispatcher)
{
$this->components = $components;
$this->cacheService = $cacheService;
$this->dispatcher = $dispatcher;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -230,13 +229,9 @@ protected function runProcessors(ConfigurationObjectInstance $definitionObject)
* Sends a signal to allow external API to manage their own definition
* components.
*/
protected function sendComponentsSignal()
protected function sendComponentsSignal(): void
{
$this->dispatcher->dispatch(
self::class,
self::COMPONENTS_SIGNAL,
[$this->components]
);
$this->eventDispatcher->dispatch(new DefinitionBuilderManageComponentEvent($this->components));
}

/**
Expand All @@ -245,14 +240,10 @@ protected function sendComponentsSignal()
* Please be aware that this signal is sent only if no error was found when
* the definition was built.
*/
protected function sendDefinitionBuiltSignal()
protected function sendDefinitionBuiltSignal(): void
{
if (!$this->definitionObject->getValidationResult()->hasErrors()) {
$this->dispatcher->dispatch(
self::class,
self::DEFINITION_BUILT_SIGNAL,
[$this->definitionObject->getObject()]
);
$this->eventDispatcher->dispatch(new DefinitionBuilderBuiltEvent($this->definitionObject->getObject()));
}
}
}
Loading