Skip to content

Commit

Permalink
Honeypot update script
Browse files Browse the repository at this point in the history
  • Loading branch information
robdekort committed Feb 9, 2024
1 parent 2070b1e commit 79560c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ServiceProvider extends AddonServiceProvider
\Studio1902\PeakTools\Updates\UpdateFormErrorHandling::class,
\Studio1902\PeakTools\Updates\UpdateButtonAttributeTags::class,
\Studio1902\PeakTools\Updates\UpdateImagesBlueprintWithExemptToggle::class,
\Studio1902\PeakTools\Updates\UpdateHoneypotField::class,
];

public function bootAddon()
Expand Down
31 changes: 31 additions & 0 deletions src/Updates/UpdateHoneypotField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Studio1902\PeakTools\Updates;

use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use Statamic\UpdateScripts\UpdateScript;

class UpdateHoneypotField extends UpdateScript
{
public function shouldUpdate($newVersion, $oldVersion)
{
return $this->isUpdatingTo('4.4.2');
}

public function update()
{
$view = base_path("resources/views/page_builder/_form.antlers.html");

if (File::exists($view)) {
$contents = Str::of(File::get($view))
->replace('name="{{ honeypot }}"', 'name="{{ honeypot }}" x-model="form.{{ honeypot }}"');

File::put($view, $contents);

$this->console()->info('Added `x-model="form.{{ honeypot }}"` to the honeypot input field in `/views/page_builder/_form.antlers.html`. Update this manually for any other form files you may have.');
} else {
$this->console()->info('add `x-model="form.{{ honeypot }}"` to the honeypot field in all your form partials.');
}
}
}

0 comments on commit 79560c5

Please sign in to comment.