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

Fix taxonomy not loading when using site subdirectory #3541

Merged
merged 1 commit into from
Apr 16, 2021
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
7 changes: 1 addition & 6 deletions src/Taxonomies/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,7 @@ public function uri()
{
$site = Site::current();

$prefix = $this->collection() ? $this->collection()->uri($site->handle()) : $site->url();

// If the site's url was defined absolutely, it'll be absolute.
// We need it relative. Perhaps the url method should return
// a relative url already, but that's a problem for later.
$prefix = URL::makeRelative($prefix);
$prefix = $this->collection() ? $this->collection()->uri($site->handle()) : '/';

return URL::tidy($prefix.str_replace('_', '-', '/'.$this->handle));
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Data/Taxonomies/TaxonomyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Statamic\Contracts\Entries\Entry as EntryContract;
use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
use Statamic\Facades\Site;
use Statamic\Fields\Blueprint;
use Statamic\Support\Arr;
use Statamic\Taxonomies\Taxonomy;
use Tests\PreventSavingStacheItemsToDisk;
use Tests\TestCase;
Expand Down Expand Up @@ -111,6 +113,20 @@ public function it_gets_the_url()
$this->assertEquals('http://localhost/tags', $taxonomy->absoluteUrl());
}

/** @test */
public function it_gets_the_url_when_the_site_is_using_a_subdirectory()
{
$config = config('statamic.sites');
Arr::set($config, 'sites.en.url', '/subdirectory/');
Site::setConfig($config);

$taxonomy = (new Taxonomy)->handle('tags');

$this->assertEquals('/tags', $taxonomy->uri());
$this->assertEquals('/subdirectory/tags', $taxonomy->url());
$this->assertEquals('http://localhost/subdirectory/tags', $taxonomy->absoluteUrl());
}

/** @test */
public function it_gets_the_url_with_a_collection()
{
Expand Down