-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
return [ | ||
'enable_redirection' => true, | ||
|
||
'type' => 'redirect', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div id="sticky-banner" tabindex="-1" | ||
class="fixed top-0 start-0 z-50 flex justify-between w-full p-4 border-b border-gray-200 bg-gray-50"> | ||
<div class="flex items-center mx-auto"> | ||
<p class="flex items-center text-sm font-normal text-gray-500"> | ||
<span | ||
class="inline-flex p-1 me-3 bg-gray-200 rounded-full w-6 h-6 items-center justify-center flex-shrink-0"> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" | ||
class="w-6 h-6"> | ||
<path stroke-linecap="round" stroke-linejoin="round" | ||
d="M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5" /> | ||
</svg> | ||
<span class="sr-only">Flag</span> | ||
</span> | ||
<span>This page is also available in | ||
<a href="{{ url }}" title="Page in {{site:name }}"> | ||
{{ site:name }} | ||
</a> | ||
</span> | ||
</p> | ||
</div> | ||
<div class="flex items-center"> | ||
<button data-dismiss-target="#sticky-banner" type="button" | ||
class="flex-shrink-0 inline-flex justify-center w-7 h-7 items-center text-gray-400 hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 dark:hover:bg-gray-600 dark:hover:text-white"> | ||
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14"> | ||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" | ||
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" /> | ||
</svg> | ||
<span class="sr-only">Close banner</span> | ||
</button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Reach\LocaleLander\Tags; | ||
|
||
use Reach\LocaleLander\Facades\LocaleHelper; | ||
use Statamic\Tags\Tags; | ||
|
||
class LocaleBanner extends Tags | ||
{ | ||
public function index() | ||
{ | ||
$helper = LocaleHelper::boot(request()); | ||
|
||
if ($helper->hasCookie() || | ||
$helper->isCurrentLocaleCorrect()) { | ||
|
||
return $this->notFound(); | ||
} | ||
|
||
$site = $helper->getMatchingSite(); | ||
if (! $site) { | ||
return $this->notFound(); | ||
} | ||
|
||
$content = $helper->findContentInLocale($site); | ||
if ($content) { | ||
return [ | ||
'entry' => $content->toAugmentedArray(['title', 'url']), | ||
'site' => $site, | ||
]; | ||
} | ||
|
||
return $this->notFound(); | ||
} | ||
|
||
protected function notFound() | ||
{ | ||
return [ | ||
'entry' => false, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
use Reach\LocaleLander\Tags\LocaleBanner; | ||
use Reach\LocaleLander\Tests\CreatesEntries; | ||
use Reach\LocaleLander\Tests\FakesViews; | ||
use Reach\LocaleLander\Tests\PreventSavingStacheItemsToDisk; | ||
use Reach\LocaleLander\Tests\TestCase; | ||
use Statamic\Facades; | ||
use Statamic\Facades\Antlers; | ||
|
||
class LocaleBannerTagTest extends TestCase | ||
{ | ||
use CreatesEntries, FakesViews, PreventSavingStacheItemsToDisk; | ||
|
||
public $collection; | ||
|
||
public $tag; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->collection = Facades\Collection::make('pages') | ||
->defaultPublishState('published') | ||
->sites(['en', 'fr', 'de', 'gr']) | ||
->routes('{parent_uri}/{slug}') | ||
->structureContents([ | ||
'root' => true, | ||
'max_depth' => 1, | ||
]) | ||
->save(); | ||
|
||
$this->tag = (new LocaleBanner) | ||
->setParser(Antlers::parser()) | ||
->setContext([]); | ||
} | ||
|
||
/** @test */ | ||
public function the_tag_returns_the_entry_if_locale_exists() | ||
{ | ||
$this->createMultisiteEntries(); | ||
|
||
Facades\Stache::clear(); | ||
|
||
ray($this->tag->index()); | ||
} | ||
|
||
private function setTagParameters($parameters) | ||
{ | ||
$this->tag->setParameters($parameters); | ||
} | ||
} |