Skip to content

Commit

Permalink
Merge pull request #51 from marcorieser/restore-site-trait
Browse files Browse the repository at this point in the history
RestoreCurrentSite Trait
  • Loading branch information
jonassiewertsen authored Mar 8, 2024
2 parents 4983116 + e085097 commit bbf2325
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/RestoreCurrentSite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Jonassiewertsen\Livewire;

use Illuminate\Support\Facades\Date;
use Livewire\Attributes\Locked;
use Statamic\Facades\Site;
use Statamic\Statamic;

trait RestoreCurrentSite
{
#[Locked]
public string $siteHandle = "";

public function mountRestoreCurrentSite(): void
{
$this->siteHandle = Site::current()->handle();
}

public function hydrateRestoreCurrentSite(): void
{
Site::setCurrent($this->siteHandle);

$site = Site::current();

setlocale(LC_TIME, $site->locale());
app()->setLocale($site->lang());
Date::setToStringFormat(Statamic::dateFormat());
}
}

0 comments on commit bbf2325

Please sign in to comment.