Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save h3nn3s/866dd7fae0696c8c9d762789281a88ea to your computer and use it in GitHub Desktop.
Save h3nn3s/866dd7fae0696c8c9d762789281a88ea to your computer and use it in GitHub Desktop.
TYPO3 powermail DataProcessor: Convert checkbox positions to there decimal represenation
<?php
namespace HenrikZiegenhain\MyExt\DataProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2018 Henrik Ziegenhain <henrik@ziegenhain.me>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use In2code\Powermail\DataProcessor\AbstractDataProcessor;
use In2code\Powermail\Domain\Model\Mail;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/**
* Class ConvertApplicationAreaValuesToBinary
* @package HenrikZiegenhain\MyExt\DataProcessor
*/
class ConvertApplicationAreaValuesToBinaryDataProcessor extends AbstractDataProcessor
{
/**
* @var Mail
*/
protected $mail;
/**
* Convert values
*/
public function convertApplicationAreaValuesToBinaryDataProcessor()
{
// Settings und Konfigurationen
$settings = $this->getSettings();
$configuration = $this->getConfiguration();
// Die eigentliche uid des PowerMail-Formulars
$powerMailFormUid = $settings['main']['form'];
// Die spezielle Konfiguration für dieses Formular, falls vorhanden
$mailformConfig = $configuration[$powerMailFormUid];
// Wenn keine Konfiguration vorhanden, dann Abbruch!
if ($mailformConfig['active'] !== '1') return;
// Zugriff auf Formular-Daten
$checkboxValues = $this->getMail()->getAnswersByFieldMarker()['mycheckboxes']->getValue();
$checkboxIntValue = 0;
foreach ($checkboxValues as $checkboxValue) {
$checkboxIntValue += (int)$checkboxValue;
}
$this->getMail()->getAnswersByFieldMarker()['mycheckboxes']->setValue($checkboxIntValue);
return true;
}
}
plugin.tx_powermail.settings.setup {
dataProcessors {
30 {
class = HenrikZiegenhain\MyExt\DataProcessor\ConvertApplicationAreaValuesToBinaryDataProcessor
config {
# this key represents the FORM UID, where to activate the DataProcessor
8 {
active = 1
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment