Skip to content

Commit

Permalink
Fix taxonomy not loading when using site subdirectory (#3541)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Apr 16, 2021
1 parent 8723710 commit 5dc9a27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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

0 comments on commit 5dc9a27

Please sign in to comment.