Skip to content

Commit

Permalink
Store form data (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Aug 21, 2024
1 parent dbcb234 commit 4d41965
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require": {
"php": "^8.1",
"statamic/cms": "^5.17"
"statamic/cms": "^5.18"
},
"require-dev": {
"doctrine/dbal": "^3.8",
Expand Down
2 changes: 2 additions & 0 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static function fromModel(Model $model)
->store($model->settings['store'] ?? null)
->email($model->settings['email'] ?? null)
->honeypot($model->settings['honeypot'] ?? null)
->data($model->settings['data'] ?? [])
->model($model);
}

Expand All @@ -39,6 +40,7 @@ public static function makeModelFromContract(Contract $source)
'store' => $source->store(),
'email' => $source->email(),
'honeypot' => $source->honeypot(),
'data' => $source->data(),
],
]);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Forms/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades;
use Statamic\Support\Arr;
use Tests\TestCase;

class FormTest extends TestCase
Expand Down Expand Up @@ -62,4 +63,12 @@ public function deleting_a_form_removes_the_blink_cache()
$this->assertNull(Facades\Blink::get('eloquent-forms-test'));
$this->assertNull(Facades\Blink::get('eloquent-forms'));
}

#[Test]
public function it_stores_form_data()
{
$form = tap(Facades\Form::make('test')->title('Test form')->data(['some' => 'data']))->save();

$this->assertSame(['some' => 'data'], Arr::get($form->model(), 'settings.data'));
}
}

0 comments on commit 4d41965

Please sign in to comment.