Commit 064f13d7 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

[REFACTOR] Rename Additional Field Provider Class

parent 5bbec80a
<?php
namespace T3o\T3oMembership\Task;
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* 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!
*/
/**
* Class Tx_T3oMembership_Task_ImportMembersAdditionalFields
*
* @author Thomas Löffler <thomas.loeffler@typo3.org>
*/
class ImportMembersAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
{
/**
* Gets additional fields to render in the form to add/edit a task
*
* @param array $taskInfo
* @param Task $task
* @param SchedulerModuleController $schedulerModule
* @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '',
* 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
*/
public function getAdditionalFields(array &$taskInfo, Task $task, SchedulerModuleController $schedulerModule)
{
$additionalFields = array();
// adds field for setting file path for CSV file to import
$importFile = '';
$membershipStoragePid = 0;
if ($task instanceof Task) {
$importFile = htmlspecialchars($task->getImportFile());
$membershipStoragePid = (int)$task->getMembershipStoragePid();
}
$additionalFields['importFile'] = array(
'code' => '<input type="text" name="tx_scheduler[importFile]" value="' . $importFile . '" />',
'label' => LocalizationUtility::translate('importFile', 't3omembership')
);
// adds field for setting storage PID
$additionalFields['storagePid'] = array(
'code' => '<input type="text" name="tx_scheduler[storagePid]" value="' . $membershipStoragePid . '" />',
'label' => LocalizationUtility::translate('storagePid', 't3omembership')
);
return $additionalFields;
}
/**
* Validates the additional fields' values
*
* @param array $submittedData
* @param SchedulerModuleController $schedulerModule
* @return boolean
*/
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
{
// only validation for importFile would be a file_exists, but it will be validated in the task itself
return true;
}
/**
* Takes care of saving the additional fields' values in the task's object
*
* @param array $submittedData
* @param Task $task
* @return void
*/
public function saveAdditionalFields(array $submittedData, Task $task)
{
$task->setImportFile($submittedData['importFile']);
$task->setMembershipStoragePid($submittedData['storagePid']);
}
}
\ No newline at end of file
<?php
namespace T3o\T3oMembership\Task;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* 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!
*/
/**
* Class ImportMembersTaskAdditionalFieldProvider
*
* @author Thomas Löffler <thomas.loeffler@typo3.org>
*/
class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
{
/**
* Gets additional fields to render in the form to add/edit a task
*
* @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 \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();
// adds field for setting file path for CSV file to import
$fieldID = 'task_importFile';
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[importFile]" id="' . $fieldID . '" value="' . htmlspecialchars($task->importFile) . '" size="30">';
// adds field for setting storage PID
$additionalFields[$fieldID] = array(
'code' => $fieldCode,
'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:importFile',
);
$fieldID = 'task_storagePid';
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[membershipStoragePid]" id="' . $fieldID . '" value="' . (int)$task->membershipStoragePid . '" size="30">';
// adds field for setting storage PID
$additionalFields[$fieldID] = array(
'code' => $fieldCode,
'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:storagePid'
);
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 bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
{
// only validation for importFile would be a file_exists, but it will be validated in the task itself
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
*/
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task){
$task->importFile = $submittedData['importFile'];
$task->membershipStoragePid = $submittedData['membershipStoragePid'];
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment