Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,11 @@ public function getQueryableValue(string $field)
return $this->value('authors');
}

// Avoid resolving the Site object.
if ($field === 'site') {
return $this->locale();
}

// Reset the cached uri so it gets recalculated.
if ($field === 'uri') {
Blink::store('entry-uris')->forget($this->id());
Expand Down
8 changes: 7 additions & 1 deletion src/Sites/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Sites;

use Statamic\Contracts\Data\Augmentable;
use Statamic\Contracts\Query\QueryableValue;
use Statamic\Data\HasAugmentedData;
use Statamic\Facades\Parse;
use Statamic\Facades\URL;
Expand All @@ -14,7 +15,7 @@
use Statamic\View\Antlers\Language\Utilities\StringUtilities;
use Statamic\View\Cascade;

class Site implements Augmentable
class Site implements Augmentable, QueryableValue
{
use HasAugmentedData;

Expand Down Expand Up @@ -163,6 +164,11 @@ public function rawConfig()
return $this->rawConfig;
}

public function toQueryableValue()
{
return $this->handle();
}

public function __toString()
{
return $this->handle();
Expand Down
3 changes: 3 additions & 0 deletions src/Stache/Indexes/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Statamic\Stache\Indexes;

/**
* @deprecated Entries resolve their site handle in getQueryableValue(), so the regular value index is used.
*/
class Site extends Value
{
public function getItemValue($item)
Expand Down
3 changes: 3 additions & 0 deletions src/Stache/Indexes/Terms/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Statamic\Stache\Indexes\Terms;

/**
* @deprecated Terms resolve their site handle in getQueryableValue(), so the regular value index is used.
*/
class Site extends Value
{
public function getItemValue($item)
Expand Down
2 changes: 1 addition & 1 deletion src/Stache/Stores/CollectionEntriesStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected function storeIndexes()
'collectionHandle',
'published',
'title',
'site' => Indexes\Site::class,
'site',
'origin' => Indexes\Origin::class,
'parent' => Indexes\Parents::class,
'uri',
Expand Down
1 change: 0 additions & 1 deletion src/Stache/Stores/FormSubmissionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class FormSubmissionsStore extends ChildStore
{
protected $valueIndex = Value::class;
protected $storeIndexes = [
'form',
'date',
];

Expand Down
3 changes: 1 addition & 2 deletions src/Stache/Stores/TaxonomyTermsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class TaxonomyTermsStore extends ChildStore
protected $valueIndex = Value::class;
protected $storeIndexes = [
'slug',
'taxonomy',
'associations' => Indexes\Terms\Associations::class,
'site' => Indexes\Terms\Site::class,
'site',
];

public function getItemFilter(SplFileInfo $file)
Expand Down
5 changes: 5 additions & 0 deletions src/Taxonomies/LocalizedTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ public function repository()

public function getQueryableValue(string $field)
{
// Avoid resolving the Site object.
if ($field === 'site') {
return $this->locale();
}

if (in_array($method = Str::camel($field), $this->queryableMethods())) {
return $this->{$method}();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Data/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,13 @@ public function entries_can_be_serialized_after_resolving_values()

$this->assertSame('entry-slug', $unserialized->slug);
}

#[Test]
public function it_gets_the_site_handle_as_the_queryable_site_value()
{
$this->assertSame('en', (new Entry)->locale('en')->getQueryableValue('site'));
$this->assertSame('removed', (new Entry)->locale('removed')->getQueryableValue('site'));
}
}

class CustomEntry extends Entry
Expand Down
7 changes: 7 additions & 0 deletions tests/Data/Taxonomies/LocalizedTermTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,11 @@ public function it_dispatches_localized_term_deleted_event()

Event::assertDispatched(LocalizedTermDeleted::class, fn ($event) => $event->term === $localized);
}

#[Test]
public function it_gets_the_site_handle_as_the_queryable_site_value()
{
$this->assertSame('en', (new LocalizedTerm(new Term, 'en'))->getQueryableValue('site'));
$this->assertSame('removed', (new LocalizedTerm(new Term, 'removed'))->getQueryableValue('site'));
}
}
12 changes: 12 additions & 0 deletions tests/Sites/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Tests\Sites;

use PHPUnit\Framework\Attributes\Test;
use Statamic\Contracts\Query\QueryableValue;
use Statamic\Data\AugmentedCollection;
use Statamic\Facades\Antlers;
use Statamic\Query\ResolveValue;
use Statamic\Sites\Site;
use Tests\TestCase;

Expand Down Expand Up @@ -366,4 +368,14 @@ public function it_gets_attributes()
$this->assertNull($site->attribute('unknown'));
$this->assertNull($site->attribute('charlie.unknown'));
}

#[Test]
public function it_resolves_to_its_handle_when_queried()
{
$site = new Site('en', []);

$this->assertInstanceOf(QueryableValue::class, $site);
$this->assertSame('en', $site->toQueryableValue());
$this->assertSame('en', (new ResolveValue)(['site' => $site], 'site'));
}
}
Loading