Skip to content

Instantly share code, notes, and snippets.

@georgringer
Last active December 14, 2020 19:16
Show Gist options
  • Select an option

  • Save georgringer/eb9d84ecdcb489ea8d6fda36eaef3a07 to your computer and use it in GitHub Desktop.

Select an option

Save georgringer/eb9d84ecdcb489ea8d6fda36eaef3a07 to your computer and use it in GitHub Desktop.

Revisions

  1. georgringer revised this gist Dec 14, 2020. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions EmailValidator.php
    Original 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;
    use TYPO3\CMS\Extbase\Error\Error;

    class EmailValidator extends AbstractValidator
    {

    protected $configuration = [];

    /**
    *
    * @param Mail $mail
    * @return Result
    * @return bool
    */
    public function validate($mail)
    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) {
    foreach ($answerValues as $value) {
    if ($value !== $answerValues[0]) {
    $isSame = false;
    }
    }
    if (!$isSame) {
    $result->addError(new Error('Email-Adresse ist nicht ident', $fields[1]));
    $this->setErrorAndMessage($firstAnswerField, 'Email-Adresse ist nicht ident');
    }
    }
    }
    return $result;
    return $this->isValidState();
    }
    }
    }
  2. georgringer created this gist Dec 10, 2020.
    47 changes: 47 additions & 0 deletions EmailValidator.php
    Original 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;
    }
    }
    14 changes: 14 additions & 0 deletions powermail.typoscript
    Original 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
    }
    }
    }
    }