我的调度程序任务获得了一个额外的字段。选择此选择域中的选项工作正确,相应地执行任务。但是,如果我打开任务来配置它,原始配置不会显示,它始终显示我的选择字段中的第一个选项。
这是我的班级:
class AdditionalFieldProviderSocialHubImporter implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
/**
* 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 object $task When editing, reference to the current task object. Null when adding.
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject 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) {
$additionalFields = array();
if (empty($taskInfo['replaceVideoStreams']) || $taskInfo['replaceVideoStreams'] === 'false') {
$taskInfo['replaceVideoStreams'] = 'false';
$optionTrue = '';
$optionFalse = 'selected';
} else {
$optionTrue = 'selected';
$optionFalse = '';
}
// Write the code for the field
$fieldID = 'task_replaceVideoStreams';
$fieldCode = '<select name="tx_scheduler[replaceVideoStreams]" id="' . $fieldID . '">
<option value="false" '.$optionFalse.'>false</option>
<option value="true" '.$optionTrue.'>true</option>
</select>';
$additionalFields[$fieldID] = array(
'code' => $fieldCode,
'label' => 'LLL:EXT:exutectmaps/Resources/Private/Language/locallang.xlf:tx_exutecmaps_domain_model_feeds.replaceVideoStreams',
'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 \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
return TRUE;
}
/**
* 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
* @return void
*/
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
$task->replaceVideoStreams = $submittedData['replaceVideoStreams'];
}
}
答案 0 :(得分:0)
在getAdditionalFields()
方法的开头添加以下内容 - $taskInfo
只包含客户端提交的值,如果添加或编辑任务,则必须先初始化这些值。
// assign default value
if (!isset($taskInfo['replaceVideoStreams'])) {
$taskInfo['replaceVideoStreams'] = 'false';
// assign value of task currently being edited
if ($parentObject->CMD === 'edit') {
$taskInfo['replaceVideoStreams'] = $task->replaceVideoStreams;
}
}
example in the TYPO3 core的代码与此类似,并且另外涉及add
命令。