103 lines
4.4 KiB
PHP
103 lines
4.4 KiB
PHP
<?php
|
|
namespace TYPO3\CMS\Scheduler\Example;
|
|
|
|
/*
|
|
* 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\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
|
|
* @internal This class is an example is not considered part of the Public TYPO3 API.
|
|
*/
|
|
class TestTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvider
|
|
{
|
|
/**
|
|
* This method is used to define new fields for adding or editing a task
|
|
* In this case, it adds an email field
|
|
*
|
|
* @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 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, SchedulerModuleController $schedulerModule)
|
|
{
|
|
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
|
|
|
|
// Initialize extra field value
|
|
if (empty($taskInfo['email'])) {
|
|
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 ($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 {
|
|
// Otherwise set an empty value, as it will not be used anyway
|
|
$taskInfo['email'] = '';
|
|
}
|
|
}
|
|
// Write the code for the field
|
|
$fieldID = 'task_email';
|
|
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['email']) . '" size="30">';
|
|
$additionalFields = [];
|
|
$additionalFields[$fieldID] = [
|
|
'code' => $fieldCode,
|
|
'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email',
|
|
'cshKey' => '_MOD_system_txschedulerM1',
|
|
'cshLabel' => $fieldID
|
|
];
|
|
return $additionalFields;
|
|
}
|
|
|
|
/**
|
|
* This method checks any additional data that is relevant to the specific task
|
|
* 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 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, SchedulerModuleController $schedulerModule)
|
|
{
|
|
$submittedData['email'] = trim($submittedData['email']);
|
|
if (empty($submittedData['email'])) {
|
|
$this->addMessage(
|
|
$GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noEmail'),
|
|
FlashMessage::ERROR
|
|
);
|
|
$result = false;
|
|
} else {
|
|
$result = true;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* This method is used to save any additional input into the current task object
|
|
* 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
|
|
*/
|
|
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
|
|
{
|
|
$task->email = $submittedData['email'];
|
|
}
|
|
}
|