Commit 394dac69 authored by Łukasz Uznański's avatar Łukasz Uznański Committed by Mathias Brodala
Browse files

[TASK] Use ServerRequestInterface in SchedulerModuleController

* replace usages of _GP, getIndpEnv
* add return hints

Resolves: #84387
Releases: master
Change-Id: I156f9005c132ab91abfbd72b97084ede6708d0dc
Reviewed-on: https://review.typo3.org/56264


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Robert van Kammen's avatarRobert van Kammen <rvkammen@hotmail.com>
Tested-by: Robert van Kammen's avatarRobert van Kammen <rvkammen@hotmail.com>
Reviewed-by: Mathias Brodala's avatarMathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala's avatarMathias Brodala <mbrodala@pagemachine.de>
parent aab39102
.. include:: ../../Includes.txt
=================================================================================
Deprecation: #84387 - Deprecated method and property in SchedulerModuleController
=================================================================================
See :issue:`84387`
Description
===========
The property :php:`$CMD` and the method :php:`addMessage()` in the :php:`SchedulerModuleController`
have been marked as deprecated and will be removed in TYPO3 v10.
Impact
======
Accessing the property or calling the method will trigger a deprecation warning.
Affected Installations
======================
Third party code which accesses the property directly or calls the method.
Migration
=========
Instead of accessing the property :php:`SchedulerModuleController::$CMD`, the method :php:`getCurrentAction()`
must be used which returns an instance of the :php:`TYPO3\CMS\Scheduler\Task\Enumeration\Action` enumeration.
Instead of calling the method :php:`SchedulerModuleController::addMessage()`, in your additional field providers
you can now extend :php:`TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider` which provides a method :php:`addMessage()`
with the same API like before.
.. index:: FullyScanned
......@@ -15,13 +15,14 @@ namespace TYPO3\CMS\Extbase\Scheduler;
*/
use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
/**
* Field provider for Extbase CommandController Scheduler task
*/
class FieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
class FieldProvider implements AdditionalFieldProviderInterface
{
/**
* @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager
......
......@@ -2431,4 +2431,11 @@ return [
'Deprecation-85451-ContentObjectRenderer-calcIntExplodeDeprecated.rst'
],
],
'TYPO3\CMS\Scheduler\Classes\Controller\SchedulerModuleController->addMessage' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Deprecation-84387-DeprecatedMethodAndPropertyInSchedulerModuleController.rst',
],
],
];
......@@ -637,4 +637,9 @@ return [
'Deprecation-85196-ProtectSetupModuleController.rst'
],
],
'TYPO3\CMS\Scheduler\Controller\SchedulerModuleController->CMD' => [
'restFiles' => [
'Deprecation-84387-DeprecatedMethodAndPropertyInSchedulerModuleController.rst'
],
],
];
......@@ -18,14 +18,15 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* This class provides Scheduler Additional Field plugin implementation
*/
class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface
class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvider
{
/**
* Default language file of the extension linkvalidator
......@@ -46,55 +47,59 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
{
$additionalFields = [];
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
if (empty($taskInfo['configuration'])) {
if ($schedulerModule->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['configuration'] = $taskInfo['linkvalidator']['configuration'];
} elseif ($schedulerModule->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['configuration'] = $task->getConfiguration();
} else {
$taskInfo['configuration'] = $task->getConfiguration();
}
}
if (empty($taskInfo['depth'])) {
if ($schedulerModule->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['depth'] = $taskInfo['linkvalidator']['depth'];
} elseif ($schedulerModule->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['depth'] = $task->getDepth();
} else {
$taskInfo['depth'] = $task->getDepth();
}
}
if (empty($taskInfo['page'])) {
if ($schedulerModule->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['page'] = $taskInfo['linkvalidator']['page'];
} elseif ($schedulerModule->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['page'] = $task->getPage();
} else {
$taskInfo['page'] = $task->getPage();
}
}
if (empty($taskInfo['email'])) {
if ($schedulerModule->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['email'] = $taskInfo['linkvalidator']['email'];
} elseif ($schedulerModule->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['email'] = $task->getEmail();
} else {
$taskInfo['email'] = $task->getEmail();
}
}
if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
if ($schedulerModule->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['emailOnBrokenLinkOnly'] = $taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] ? $taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] : 1;
} elseif ($schedulerModule->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
} else {
$taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
}
}
if (empty($taskInfo['emailTemplateFile'])) {
if ($schedulerModule->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['emailTemplateFile'] = $taskInfo['linkvalidator']['emailTemplateFile'] ? $taskInfo['linkvalidator']['emailTemplateFile'] : 'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html';
} elseif ($schedulerModule->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
} else {
$taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
......@@ -233,7 +238,7 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt
foreach ($emailList as $emailAdd) {
if (!GeneralUtility::validEmail($emailAdd)) {
$isValid = false;
$schedulerModule->addMessage(
$this->addMessage(
$lang->sL($this->languageFile . ':tasks.validate.invalidEmail'),
FlashMessage::ERROR
);
......@@ -244,14 +249,14 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt
$row = BackendUtility::getRecord('pages', (int)$submittedData['linkvalidator']['page'], '*', '', false);
if (empty($row)) {
$isValid = false;
$schedulerModule->addMessage(
$this->addMessage(
$lang->sL($this->languageFile . ':tasks.validate.invalidPage'),
FlashMessage::ERROR
);
}
if ($submittedData['linkvalidator']['depth'] < 0) {
$isValid = false;
$schedulerModule->addMessage(
$this->addMessage(
$lang->sL($this->languageFile . ':tasks.validate.invalidDepth'),
FlashMessage::ERROR
);
......
......@@ -15,14 +15,16 @@ namespace TYPO3\CMS\Recycler\Task;
*/
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* A task that should be run regularly that deletes
* datasets flagged as "deleted" from the DB.
*/
class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
class CleanerFieldProvider extends AbstractAdditionalFieldProvider
{
/**
* Gets additional fields to render in the form to add/edit a task
......@@ -34,7 +36,9 @@ class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProvid
*/
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
{
if ($schedulerModule->CMD === 'edit') {
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['RecyclerCleanerTCA'] = $task->getTcaTables();
$taskInfo['RecyclerCleanerPeriod'] = $task->getPeriod();
}
......@@ -94,8 +98,8 @@ class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProvid
*/
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
{
$validPeriod = $this->validateAdditionalFieldPeriod($submittedData['RecyclerCleanerPeriod'], $schedulerModule);
$validTca = $this->validateAdditionalFieldTca($submittedData['RecyclerCleanerTCA'], $schedulerModule);
$validPeriod = $this->validateAdditionalFieldPeriod($submittedData['RecyclerCleanerPeriod']);
$validTca = $this->validateAdditionalFieldTca($submittedData['RecyclerCleanerTCA']);
return $validPeriod && $validTca;
}
......@@ -104,27 +108,25 @@ class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProvid
* Validates the selected Tables
*
* @param array $tca The given TCA-tables as array
* @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module
* @return bool TRUE if validation was ok, FALSE otherwise
*/
protected function validateAdditionalFieldTca($tca, SchedulerModuleController $schedulerModule)
protected function validateAdditionalFieldTca($tca)
{
return $this->checkTcaIsNotEmpty($tca, $schedulerModule) && $this->checkTcaIsValid($tca, $schedulerModule);
return $this->checkTcaIsNotEmpty($tca) && $this->checkTcaIsValid($tca);
}
/**
* Checks if the array is empty
*
* @param array $tca The given TCA-tables as array
* @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module
* @return bool TRUE if validation was ok, FALSE otherwise
*/
protected function checkTcaIsNotEmpty($tca, SchedulerModuleController $schedulerModule)
protected function checkTcaIsNotEmpty($tca)
{
if (is_array($tca) && !empty($tca)) {
$validTca = true;
} else {
$schedulerModule->addMessage(
$this->addMessage(
$this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCAempty'),
FlashMessage::ERROR
);
......@@ -138,16 +140,15 @@ class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProvid
* Checks if the given tables are in the TCA
*
* @param array $tca The given TCA-tables as array
* @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module
* @return bool TRUE if validation was ok, FALSE otherwise
*/
protected function checkTcaIsValid(array $tca, SchedulerModuleController $schedulerModule)
protected function checkTcaIsValid(array $tca)
{
$checkTca = false;
foreach ($tca as $tcaTable) {
if (!isset($GLOBALS['TCA'][$tcaTable])) {
$checkTca = false;
$schedulerModule->addMessage(
$this->addMessage(
sprintf($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCANotSet'), $tcaTable),
FlashMessage::ERROR
);
......@@ -163,15 +164,14 @@ class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProvid
* Validates the input of period
*
* @param int $period The given period as integer
* @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module
* @return bool TRUE if validation was ok, FALSE otherwise
*/
protected function validateAdditionalFieldPeriod($period, SchedulerModuleController $schedulerModule)
protected function validateAdditionalFieldPeriod($period)
{
if (!empty($period) && filter_var($period, FILTER_VALIDATE_INT) !== false) {
$validPeriod = true;
} else {
$schedulerModule->addMessage(
$this->addMessage(
$this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorPeriod'),
FlashMessage::ERROR
);
......@@ -192,7 +192,7 @@ class CleanerFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProvid
{
if (!$task instanceof CleanerTask) {
throw new \InvalidArgumentException(
'Expected a task of type \TYPO3\CMS\Recycler\Task\CleanerTask, but got ' . get_class($task),
'Expected a task of type ' . CleanerTask::class . ', but got ' . get_class($task),
1329219449
);
}
......
......@@ -41,7 +41,7 @@ class CleanerFieldProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTes
->getMock();
$languageServiceMock->expects($this->any())->method('sL')->will($this->returnValue('titleTest'));
$this->subject = $this->getMockBuilder(CleanerFieldProvider::class)
->setMethods(['getLanguageService'])
->setMethods(['getLanguageService', 'addMessage'])
->getMock();
$this->subject->expects($this->any())->method('getLanguageService')->willReturn($languageServiceMock);
}
......@@ -95,8 +95,8 @@ class CleanerFieldProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTes
'RecyclerCleanerTCA' => ['pages']
];
$scheduleModuleControllerMock = $this->getScheduleModuleControllerMock(['addMessage']);
$scheduleModuleControllerMock->expects($this->atLeastOnce())
$scheduleModuleControllerMock = $this->getScheduleModuleControllerMock();
$this->subject->expects($this->atLeastOnce())
->method('addMessage')
->with($this->equalTo('titleTest'), FlashMessage::ERROR);
......@@ -128,7 +128,7 @@ class CleanerFieldProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTes
'RecyclerCleanerTCA' => $table
];
$this->subject->validateAdditionalFields($submittedData, $this->getScheduleModuleControllerMock(['addMessage']));
$this->subject->validateAdditionalFields($submittedData, $this->getScheduleModuleControllerMock());
}
/**
......
......@@ -17,15 +17,16 @@ namespace TYPO3\CMS\Reports\Task;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* Additional field to set the notification email address(es) for system health
* issue notifications.
*/
class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldProviderInterface
class SystemStatusUpdateTaskNotificationEmailField extends AbstractAdditionalFieldProvider
{
/**
* Additional fields
......@@ -51,7 +52,9 @@ class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldPro
*/
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
{
if ($schedulerModule->CMD === 'edit') {
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
$taskInfo[$this->fieldPrefix . 'NotificationAll'] = $task->getNotificationAll();
}
......@@ -100,8 +103,8 @@ class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldPro
break;
}
}
if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !$validInput) {
$schedulerModule->addMessage($this->getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), FlashMessage::ERROR);
if (!$validInput || empty($submittedData[$this->fieldPrefix . 'NotificationEmail'])) {
$this->addMessage($this->getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), FlashMessage::ERROR);
$validInput = false;
}
return $validInput;
......@@ -112,6 +115,7 @@ class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldPro
*
* @param array $submittedData An array containing the data submitted by the add/edit task form
* @param AbstractTask $task Reference to the scheduler backend module
* @throws \InvalidArgumentException
*/
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
{
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Scheduler;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Base class for providers of additional fields
*/
abstract class AbstractAdditionalFieldProvider implements AdditionalFieldProviderInterface
{
/**
* Add a flash message
*
* @param string $message the flash message content
* @param int $severity the flash message severity
*/
protected function addMessage(string $message, int $severity = FlashMessage::OK): void
{
$flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $message, '', $severity);
$service = GeneralUtility::makeInstance(FlashMessageService::class);
$queue = $service->getMessageQueueByIdentifier();
$queue->enqueue($flashMessage);
}
}
......@@ -14,12 +14,16 @@ namespace TYPO3\CMS\Scheduler\Example;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* Additional fields provider class for usage with the Scheduler's sleep task
*/
class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
class SleepTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvider
{
/**
* This method is used to define new fields for adding or editing a task
......@@ -27,17 +31,19 @@ class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\Additiona
*
* @param array $taskInfo Reference to the array containing the info used in the add/edit form
* @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
*/
public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
{
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
// Initialize extra field value
if (empty($taskInfo['sleepTime'])) {
if ($parentObject->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
// In case of new task and if field is empty, set default sleep time
$taskInfo['sleepTime'] = 30;
} elseif ($parentObject->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
// In case of edit, set to internal value if no data was submitted already
$taskInfo['sleepTime'] = $task->sleepTime;
} else {
......@@ -63,14 +69,14 @@ class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\Additiona
* If the task class is not relevant, the method is expected to return TRUE
*
* @param array $submittedData Reference to the array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
* @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
{
$submittedData['sleepTime'] = (int)$submittedData['sleepTime'];
if ($submittedData['sleepTime'] < 0) {
$parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidSleepTime'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
$this->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidSleepTime'), FlashMessage::ERROR);
$result = false;
} else {
$result = true;
......@@ -83,9 +89,9 @@ class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\Additiona
* if the task class matches
*
* @param array $submittedData Array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
* @param AbstractTask $task Reference to the current task object
*/
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
{
$task->sleepTime = $submittedData['sleepTime'];
}
......
......@@ -14,12 +14,16 @@ namespace TYPO3\CMS\Scheduler\Example;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* Additional fields provider class for usage with the Scheduler's test task
*/
class TestTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
class TestTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvider
{
/**
* This method is used to define new fields for adding or editing a task
......@@ -27,17 +31,19 @@ class TestTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\Additional
*
* @param array $taskInfo Reference to the array containing the info used in the add/edit form
* @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
*/
public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
{
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
// Initialize extra field value
if (empty($taskInfo['email'])) {
if ($parentObject->CMD === 'add') {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
// In case of new task and if field is empty, set default email address
$taskInfo['email'] = $GLOBALS['BE_USER']->user['email'];
} elseif ($parentObject->CMD === 'edit') {
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
// In case of edit, and editing a test task, set to internal value if not data was submitted already
$taskInfo['email'] = $task->email;
} else {
......@@ -63,14 +69,17 @@ class TestTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\Additional
* If the task class is not relevant, the method is expected to return TRUE
*
* @param array $submittedData Reference to the array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
* @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
{
$submittedData['email'] = trim($submittedData['email']);
if (empty($submittedData['email'])) {
$parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noEmail'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
$this->addMessage(
$GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noEmail'),
FlashMessage::ERROR
);
$result = false;
} else {
$result = true;
......@@ -85,7 +94,7 @@ class TestTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\Additional
* @param array $submittedData Array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object