Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Implement Localization interface on LocalizedTerm #9496

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
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
Loading