2017-03-17 54 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命令。