2017-03-17 81 views
0

我的调度程序任务获取附加字段。在此选择字段中选择一个选项工作正常,任务将相应执行。但是,如果我打开任务进行配置,则不显示原始配置,它始终显示我选择字段中的第一个选项。AdditionalFieldsProvider不保存配置

这是我的课:

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

添加类似以下内容到你的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命令。