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
13 changes: 13 additions & 0 deletions src/Stache/Indexes/Submissions/Site.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Statamic\Stache\Indexes\Submissions;

use Statamic\Stache\Indexes\Value;

class Site extends Value
{
public function getItemValue($item)
{
return $item->site()->handle();
}
}
2 changes: 2 additions & 0 deletions src/Stache/Stores/FormSubmissionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Facades\FormSubmission;
use Statamic\Facades\Path;
use Statamic\Facades\YAML;
use Statamic\Stache\Indexes;
use Statamic\Stache\Indexes\Value;
use Statamic\Support\Str;
use Statamic\Yaml\ParseException;
Expand All @@ -18,6 +19,7 @@ class FormSubmissionsStore extends ChildStore
protected $storeIndexes = [
'form',
'date',
'site' => Indexes\Submissions\Site::class,
];

public function getItemKey($item)
Expand Down
21 changes: 21 additions & 0 deletions tests/Forms/SubmissionQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Statamic\Contracts\Forms\Submission;
use Statamic\Facades\Form;
use Statamic\Facades\FormSubmission;
use Statamic\Facades\Site;
use Statamic\Facades\Stache;
use Tests\PreventSavingStacheItemsToDisk;
use Tests\TestCase;

Expand Down Expand Up @@ -506,6 +508,25 @@ public function it_filters_by_site()

$this->assertEquals(['b', 'c'], $this->ids(FormSubmission::query()->where('site', 'fr')->get()));
$this->assertEquals(['a'], $this->ids(FormSubmission::query()->where('site', 'en')->get()));
$this->assertEquals(['b', 'c'], $this->ids(FormSubmission::query()->where('site', Site::get('fr'))->get()));
}

#[Test]
public function it_stores_site_handles_in_the_site_index()
{
$this->setSites([
'en' => ['url' => '/'],
'fr' => ['url' => '/fr'],
]);

$form = tap(Form::make('test'))->save();
$en = tap(FormSubmission::make()->form($form)->site('en'))->save();
$fr = tap(FormSubmission::make()->form($form)->site('fr'))->save();

$this->assertSame([
"test::{$en->id()}" => 'en',
"test::{$fr->id()}" => 'fr',
], Stache::store('form-submissions')->store('test')->index('site')->items()->all());
}

#[Test]
Expand Down
Loading