1 | <?php |
||
41 | class CrawlerQueueTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface |
||
42 | { |
||
43 | /** |
||
44 | * Gets additional fields to render in the form to add/edit a task |
||
45 | * |
||
46 | * @param array $taskInfo |
||
47 | * @param CrawlerQueueTask $task |
||
48 | * @param SchedulerModuleController $schedulerModule |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) |
||
53 | { |
||
54 | $additionalFields = []; |
||
55 | |||
56 | if ($schedulerModule->CMD == 'add') { |
||
57 | $taskInfo['startPage'] = $taskInfo['startPage'] ?: 0; |
||
58 | $taskInfo['configuration'] = $taskInfo['configuration'] ?: []; |
||
59 | $taskInfo['depth'] = $taskInfo['depth'] ?: 0; |
||
60 | } |
||
61 | |||
62 | if ($schedulerModule->CMD == 'edit') { |
||
63 | $taskInfo['startPage'] = $task->startPage; |
||
64 | $taskInfo['configuration'] = $task->configuration; |
||
65 | $taskInfo['depth'] = $task->depth; |
||
66 | } |
||
67 | |||
68 | // input for startPage |
||
69 | $fieldId = 'task_startPage'; |
||
70 | $fieldCode = '<input name="tx_scheduler[startPage]" type="text" id="' . $fieldId . '" value="' . $task->startPage . '" class="form-control" />'; |
||
71 | $additionalFields[$fieldId] = [ |
||
72 | 'code' => $fieldCode, |
||
73 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.startPage' |
||
74 | ]; |
||
75 | |||
76 | // input for depth |
||
77 | $fieldId = 'task_depth'; |
||
78 | $fieldValueArray = [ |
||
79 | '0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
||
80 | '1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
||
81 | '2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
||
82 | '3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
||
83 | '4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
||
84 | '99' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'), |
||
85 | ]; |
||
86 | $fieldCode = '<select name="tx_scheduler[depth]" id="' . $fieldId . '" class="form-control">'; |
||
87 | |||
88 | foreach ($fieldValueArray as $key => $label) { |
||
89 | $fieldCode .= "\t" . '<option value="' . $key . '"' . (($key == $task->depth) ? ' selected="selected"' : '') . '>' . $label . '</option>'; |
||
90 | } |
||
91 | |||
92 | $fieldCode .= '</select>'; |
||
93 | $additionalFields[$fieldId] = [ |
||
94 | 'code' => $fieldCode, |
||
95 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.depth' |
||
96 | ]; |
||
97 | |||
98 | // combobox for configuration records |
||
99 | $recordsArray = $this->getCrawlerConfigurationRecords(); |
||
100 | $fieldId = 'task_configuration'; |
||
101 | $fieldCode = '<select name="tx_scheduler[configuration][]" multiple="multiple" id="' . $fieldId . '" class="form-control">'; |
||
102 | $fieldCode .= "\t" . '<option value=""></option>'; |
||
103 | $arraySize = count($recordsArray); |
||
104 | for ($i = 0; $i < $arraySize; $i++) { |
||
105 | $fieldCode .= "\t" . '<option ' . $this->getSelectedState($task->configuration, $recordsArray[$i]['name']) . 'value="' . $recordsArray[$i]['name'] . '">' . $recordsArray[$i]['name'] . '</option>'; |
||
|
|||
106 | } |
||
107 | $fieldCode .= '</select>'; |
||
108 | |||
109 | $additionalFields[$fieldId] = [ |
||
110 | 'code' => $fieldCode, |
||
111 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.conf' |
||
112 | ]; |
||
113 | |||
114 | return $additionalFields; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Mark current value as selected by returning the "selected" attribute |
||
119 | * |
||
120 | * @param array $configurationArray |
||
121 | * @param string $currentValue |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | protected function getSelectedState(array $configurationArray, $currentValue) |
||
137 | |||
138 | /** |
||
139 | * Get all available configuration records. |
||
140 | * |
||
141 | * @return array which contains the available configuration records. |
||
142 | */ |
||
143 | protected function getCrawlerConfigurationRecords() |
||
159 | |||
160 | /** |
||
161 | * Validates the additional fields' values |
||
162 | * |
||
163 | * @param array $submittedData |
||
164 | * @param SchedulerModuleController $schedulerModule |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule) |
||
190 | |||
191 | /** |
||
192 | * Takes care of saving the additional fields' values in the task's object |
||
193 | * |
||
194 | * @param array $submittedData |
||
195 | * @param CrawlerQueueTask|AbstractTask $task |
||
196 | * |
||
197 | * @return void |
||
198 | */ |
||
199 | public function saveAdditionalFields(array $submittedData, AbstractTask $task) |
||
205 | } |
||
206 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: