Last active
December 14, 2020 19:16
-
-
Save georgringer/eb9d84ecdcb489ea8d6fda36eaef3a07 to your computer and use it in GitHub Desktop.
Revisions
-
georgringer revised this gist
Dec 14, 2020 . 1 changed file with 11 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,42 +6,45 @@ use In2code\Powermail\Domain\Validator\AbstractValidator; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Error\Result; class EmailValidator extends AbstractValidator { protected $configuration = []; /** * * @param Mail $mail * @return bool */ public function isValid($mail) { $result = new Result(); if ((int)$this->configuration['form'] === $mail->getForm()->getUid()) { $answerValues = []; $firstAnswerField = null; $fields = GeneralUtility::trimExplode(',', $this->configuration['emailFields'], true); foreach ($mail->getAnswers() as $answer) { if ($firstAnswerField === null) { $firstAnswerField = $answer->getField(); } if (in_array($answer->getField()->getMarker(), $fields, true)) { $answerValues[] = $answer->getValue(); } } if (count($answerValues) > 1) { $isSame = true; foreach ($answerValues as $value) { if ($value !== $answerValues[0]) { $isSame = false; } } if (!$isSame) { $this->setErrorAndMessage($firstAnswerField, 'Email-Adresse ist nicht ident'); } } } return $this->isValidState(); } } -
georgringer created this gist
Dec 10, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ <?php namespace VENDOR\EXT\Domain\Powermail; use In2code\Powermail\Domain\Model\Mail; use In2code\Powermail\Domain\Validator\AbstractValidator; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Error\Result; use TYPO3\CMS\Extbase\Error\Error; class EmailValidator extends AbstractValidator { protected $configuration = []; /** * * @param Mail $mail * @return Result */ public function validate($mail) { $result = new Result(); if ((int)$this->configuration['form'] === $mail->getForm()->getUid()) { $answerValues = []; $fields = GeneralUtility::trimExplode(',', $this->configuration['emailFields'], true); foreach ($mail->getAnswers() as $answer) { if (in_array($answer->getField()->getMarker(), $fields, true)) { $answerValues[] = $answer->getValue(); } } if (count($answerValues) > 1) { $isSame = true; foreach($answerValues as $value) { if ($value !== $answerValues[0]) { $isSame = false; } } if (!$isSame) { $result->addError(new Error('Email-Adresse ist nicht ident', $fields[1])); } } } return $result; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ plugin.tx_powermail.settings.setup { validators { 1 { # Classname that should be called with method *Validator() class = VENDOR\EXT\Domain\Powermail\EmailValidator # optional: Add configuration for your PHP config { emailFields = e_mail,email2 form = 1 } } } }