Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 70 additions & 10 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use Typoheads\Formhandler\Definitions\FormhandlerExtensionConfig;
use Typoheads\Formhandler\Definitions\Severity;
use Typoheads\Formhandler\Domain\Model\Config\Finisher\MailFinisherModel;
use Typoheads\Formhandler\Domain\Model\Config\FormModel;
use Typoheads\Formhandler\Domain\Model\Config\FormUpload;
use Typoheads\Formhandler\Domain\Model\Config\FormUploadFile;
Expand Down Expand Up @@ -501,6 +502,38 @@
return $this->htmlResponse();
}

/**
* @param array<mixed> $valuesToSet
*/
private function emailOverride(array $valuesToSet): void {
/** @var false|MailFinisherModel */
$emailFinisher = array_filter($this->formConfig->finishers, function ($finisher) {
return $finisher instanceof MailFinisherModel;
})[0] ?? false;

if (!$emailFinisher) {
return;
}

// user mail conf
if (is_array($valuesToSet['user'] ?? false)) {
foreach ($valuesToSet['user'] as $key => $value) {
if (isset($emailFinisher->userMailConfig[strval($key)])) {
$emailFinisher->userMailConfig[strval($key)] = strval($value);

Check failure on line 522 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Typoheads\Formhandler\Domain\Model\Config\Finisher\MailFinisherModel::$userMailConfig (array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, ...}) does not accept array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, ...}.
}
}
}

// admin mail conf
if (is_array($valuesToSet['admin'] ?? false)) {
foreach ($valuesToSet['admin'] as $key => $value) {
if (isset($emailFinisher->adminMailConfig[strval($key)])) {
$emailFinisher->adminMailConfig[strval($key)] = strval($value);

Check failure on line 531 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Typoheads\Formhandler\Domain\Model\Config\Finisher\MailFinisherModel::$adminMailConfig (array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, ...}) does not accept array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, ...}.
}
}
}
}

// TODO: Change return type to new model of Response and Finisher name so headless knows which Finisher returned
private function finishers(): ?Response {
foreach ($this->formConfig->finishers as $finisher) {
Expand Down Expand Up @@ -549,8 +582,8 @@
$this->formConfig->step = intval(
(
(array) ($this->parsedBody[FormhandlerExtensionConfig::EXTENSION_KEY] ?? [])
)['step'] ??
$this->formConfig->session->get('step') ?: 1
)['step']
?? $this->formConfig->session->get('step') ?: 1
);

$this->formConfig->formValues = (array) ($this->formConfig->session->get('formValues') ?: []);
Expand Down Expand Up @@ -578,7 +611,7 @@

// Execute PreProcessor
foreach ($this->formConfig->preProcessors as $preProcessor) {
GeneralUtility::makeInstance($preProcessor->class())->process($this->formConfig, $preProcessor);

Check failure on line 614 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Unable to resolve the template type T in call to method static method TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance()

Check failure on line 614 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method object::process().
}

$this->formConfig->session->setMultiple(
Expand Down Expand Up @@ -674,26 +707,53 @@

foreach ($this->formConfig->conditionBlocks as $conditionBlock) {
$evaluation = $utility->conditionEvaluate($conditionBlock, $this->formConfig);

if ($evaluation) {
foreach ($conditionBlock->isTrue as $key => $value) {
if (empty($value)) {
continue;
}
if ('disableErrorCheckFields' == $key) {
foreach (explode(',', $value) ?: [] as $disableErrorCheckField) {
$this->formConfig->disableErrorCheckFields[$disableErrorCheckField] = '';
}

switch ($key) {
case 'disableErrorCheckFields':
foreach (explode(',', strval($value)) ?: [] as $disableErrorCheckField) {

Check failure on line 719 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Ternary operator condition is always true.
$this->formConfig->disableErrorCheckFields[$disableErrorCheckField] = '';

Check failure on line 720 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Typoheads\Formhandler\Domain\Model\Config\FormModel::$disableErrorCheckFields (array<string, array<string>>) does not accept array<string, array<string>|string>.
}

break;

case 'emailOverride':
case 'emailOverwrite':
$this->emailOverride((array) $value);

break;

default:
break;
}
}
} else {
foreach ($conditionBlock->else as $key => $value) {
if (empty($value)) {
continue;
}
if ('disableErrorCheckFields' == $key) {
foreach (explode(',', $value) ?: [] as $disableErrorCheckField) {
$this->formConfig->disableErrorCheckFields[$disableErrorCheckField] = '';
}

switch ($key) {
case 'disableErrorCheckFields':
foreach (explode(',', strval($value)) ?: [] as $disableErrorCheckField) {

Check failure on line 743 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Ternary operator condition is always true.
$this->formConfig->disableErrorCheckFields[$disableErrorCheckField] = '';

Check failure on line 744 in Classes/Controller/FormController.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Typoheads\Formhandler\Domain\Model\Config\FormModel::$disableErrorCheckFields (array<string, array<string>>) does not accept array<string, array<string>|string>.
}

break;

case 'emailoverride':
case 'emailoverwrite':
$this->emailOverride((array) $value);

break;

default:
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Config/Finisher/MailFinisherModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
*/
class MailFinisherModel extends AbstractFinisherModel {
/** @var array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, bccEmail: string, bccName: string, returnPath: string, templateMailHtml: string, templateMailText: string, attachments: array<string, array{fileOrField: string, mime: null|string, renameTo: null|string}>, embedFiles: array<string, array{fileOrField: string, mime: null|string, renameTo: null|string}>} */
public readonly array $adminMailConfig;
public array $adminMailConfig;

/** @var array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, bccEmail: string, bccName: string, returnPath: string, templateMailHtml: string, templateMailText: string, attachments: array<string, array{fileOrField: string, mime: null|string, renameTo: null|string}>, embedFiles: array<string, array{fileOrField: string, mime: null|string, renameTo: null|string}>} */
public readonly array $userMailConfig;
public array $userMailConfig;

private Utility $utility;

Expand Down Expand Up @@ -104,7 +104,7 @@
$parsedConfig[$option] = $value;
}

return $parsedConfig;

Check failure on line 107 in Classes/Domain/Model/Config/Finisher/MailFinisherModel.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Typoheads\Formhandler\Domain\Model\Config\Finisher\MailFinisherModel::parseEmailTypeSettings() should return array{toEmail: string, subject: string, senderEmail: string, senderName: string, replyToEmail: string, replyToName: string, ccEmail: string, ccName: string, ...} but returns non-empty-array<'attachments'|'bccEmail'|'bccName'|'ccEmail'|'ccName'|'embedFiles'|'replyToEmail'|'replyToName'|'returnPath'|'senderEmail'|'senderName'|'subject'|'templateMailHtml'|'templateMailText'|'toEmail', array<string, array{fileOrField: string, mime: string|null, renameTo: string|null}>|string>.
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@
/** @var array<string, array<string, string>> */
public readonly array $conditions;

/** @var array<string, string> */
/** @var array<string, mixed> */
public readonly array $else;

/** @var array<string, string> */
/** @var array<string, mixed> */
public readonly array $isTrue;

/**
* @param array<string, mixed> $settings
*/
public function __construct(array $settings) {
$this->conditions = $settings['conditions'] ?? [];

Check failure on line 128 in Classes/Domain/Model/Config/GeneralOptions/ConditionBlockModel.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Typoheads\Formhandler\Domain\Model\Config\GeneralOptions\ConditionBlockModel::$conditions (array<string, array<string, string>>) does not accept mixed.
$this->else = $settings['else'] ?? [];
$this->isTrue = $settings['isTrue'] ?? [];
}
Expand Down