Skip to content

Commit

Permalink
[5.x] Implement Localization interface on LocalizedTerm (#9496)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Feb 9, 2024
1 parent be95693 commit 5e6df0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Fieldtypes/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Statamic\Search\Index;
use Statamic\Search\Result;
use Statamic\Support\Arr;
use Statamic\Taxonomies\LocalizedTerm;

class Entries extends Relationship
{
Expand Down Expand Up @@ -322,7 +321,7 @@ protected function collect($value)
public function augment($values)
{
$site = Site::current()->handle();
if (($parent = $this->field()->parent()) && ($parent instanceof Localization || $parent instanceof LocalizedTerm)) {
if (($parent = $this->field()->parent()) && $parent instanceof Localization) {
$site = $parent->locale();
}

Expand Down
3 changes: 1 addition & 2 deletions src/Fieldtypes/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Statamic\Query\Scopes\Filters\Fields\Terms as TermsFilter;
use Statamic\Support\Arr;
use Statamic\Support\Str;
use Statamic\Taxonomies\LocalizedTerm;

class Terms extends Relationship
{
Expand Down Expand Up @@ -112,7 +111,7 @@ public function augment($values)
// entry, but could also be something else, like another taxonomy term.
$parent = $this->field->parent();

$site = $parent && ($parent instanceof Localization || $parent instanceof LocalizedTerm)
$site = $parent && $parent instanceof Localization
? $parent->locale()
: Site::current()->handle(); // Use the "current" site so this will get localized appropriately on the front-end.

Expand Down
9 changes: 7 additions & 2 deletions src/Taxonomies/LocalizedTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Statamic\Contracts\Auth\Protect\Protectable;
use Statamic\Contracts\Data\Augmentable;
use Statamic\Contracts\Data\Augmented;
use Statamic\Contracts\Data\Localization;
use Statamic\Contracts\GraphQL\ResolvesValues as ResolvesValuesContract;
use Statamic\Contracts\Query\ContainsQueryableValues;
use Statamic\Contracts\Search\Searchable as SearchableContract;
Expand All @@ -33,7 +34,7 @@
use Statamic\Statamic;
use Statamic\Support\Str;

class LocalizedTerm implements Arrayable, ArrayAccess, Augmentable, ContainsQueryableValues, Protectable, ResolvesValuesContract, Responsable, SearchableContract, Term
class LocalizedTerm implements Arrayable, ArrayAccess, Augmentable, ContainsQueryableValues, Localization, Protectable, ResolvesValuesContract, Responsable, SearchableContract, Term
{
use ContainsSupplementalData, HasAugmentedInstance, Publishable, ResolvesValues, Revisable, Routable, Searchable, TracksLastModified, TracksQueriedColumns, TracksQueriedRelations;

Expand Down Expand Up @@ -269,8 +270,12 @@ public function isRoot()
return $this->isDefaultLocale();
}

public function locale()
public function locale($locale = null)
{
if (func_num_args() === 1) {
throw new \Exception('The locale cannot be set on a LocalizedTerm.');
}

return $this->locale;
}

Expand Down

0 comments on commit 5e6df0a

Please sign in to comment.