Skip to content

Commit

Permalink
Fixed various bugs (#1691)
Browse files Browse the repository at this point in the history
* fix(SFT-1673): preventing propogation when whitelisting localized spam elements
* fix(SFT-1672): table layout migration check for undefined array keys
* fix(SFT-1668): observer starting before document is ready
  • Loading branch information
kjmartens authored Dec 20, 2024
2 parents 6805f2c + 82ca361 commit a425ca8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/plugin/src/Services/SpamSubmissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getSubmissionById($id): ?Submission
public function allowSpamSubmission(SpamSubmission $submission): bool
{
$submission->isSpam = false;
\Craft::$app->elements->saveElement($submission);
\Craft::$app->elements->saveElement($submission, false, false);

// HACK: this is dirty, but I wasn't able to find better way to
// quickly convert SpamSubmission to Submission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@ public function safeUp(): bool
continue;
}

if ('select' === $row['type']) {
$tableLayout[$index]['options'] = explode(';', $row['value']);
$type = $row['type'] ?? '';
$value = $row['value'] ?? '';

if ('select' === $type) {
$tableLayout[$index]['options'] = explode(';', $value);
$tableLayout[$index]['value'] = $tableLayout[$index]['options'][0] ?? '';
} else {
$tableLayout[$index]['options'] = [];
}

if ('checkbox' === $row['type']) {
$tableLayout[$index]['value'] = (bool) $row['value'];
if ('checkbox' === $type) {
$tableLayout[$index]['value'] = (bool) $value;
}

$tableLayout[$index]['placeholder'] = '';

if ('checkbox' === $row['type']) {
$tableLayout[$index]['checked'] = (bool) $row['value'];
if ('checkbox' === $type) {
$tableLayout[$index]['checked'] = (bool) $value;
} else {
$tableLayout[$index]['checked'] = false;
}
Expand Down
25 changes: 23 additions & 2 deletions packages/scripts/src/components/front-end/plugin/freeform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,5 +827,26 @@ const observer = new MutationObserver((mutations) => {
});
});

// Start the observer
observer.observe(document.body, { childList: true, subtree: true });
let retries = 0;
let timeout: ReturnType<typeof setTimeout>;

const runObserver = () => {
if (retries > 25) {
console.warn('Freeform observer timed out');
return clearTimeout(timeout);
}

// Start the observer
if (document.body) {
observer.observe(document.body, { childList: true, subtree: true });
} else {
retries++;
if (timeout) {
clearTimeout(timeout);
}

timeout = setTimeout(runObserver, 50);
}
};

runObserver();

0 comments on commit a425ca8

Please sign in to comment.