Skip to content

Commit

Permalink
Fix language default value
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Apr 20, 2024
1 parent 5062c29 commit 579e35a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion etc/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'entity' => User::class,

'srp' => [
'enabled' => true,
'enabled' => false,
'prime' => null,
'generator' => null,
'key' => null,
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Windwalker\ORM\Cast\JsonCast;
use Windwalker\ORM\EntityInterface;
use Windwalker\ORM\EntityTrait;
use Windwalker\ORM\Event\BeforeStoreEvent;
use Windwalker\ORM\Metadata\EntityMetadata;

/**
Expand Down Expand Up @@ -109,6 +110,14 @@ public static function setup(EntityMetadata $metadata): void
->targetTo(Category::class, category_id: 'id');
}

#[BeforeStoreEvent]
public static function beforeStore(BeforeStoreEvent $event): void
{
$data = &$event->getData();

$data['language'] = $data['language'] ?? null ?: '*';
}

/**
* @return int|null
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Windwalker\ORM\Attributes\PK;
use Windwalker\ORM\Attributes\Watch;
use Windwalker\ORM\Cast\JsonCast;
use Windwalker\ORM\Event\BeforeStoreEvent;
use Windwalker\ORM\Event\WatchEvent;
use Windwalker\ORM\Metadata\EntityMetadata;
use Windwalker\ORM\Nested\NestedPathableInterface;
Expand Down Expand Up @@ -91,6 +92,14 @@ public static function setup(EntityMetadata $metadata): void
//
}

#[BeforeStoreEvent]
public static function beforeStore(BeforeStoreEvent $event): void
{
$data = &$event->getData();

$data['language'] = $data['language'] ?? null ?: '*';
}

/**
* @return int|null
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Windwalker\ORM\Attributes\NestedSet;
use Windwalker\ORM\Attributes\PK;
use Windwalker\ORM\Cast\JsonCast;
use Windwalker\ORM\Event\BeforeStoreEvent;
use Windwalker\ORM\Metadata\EntityMetadata;
use Windwalker\ORM\Nested\NestedEntityInterface;
use Windwalker\ORM\Nested\NestedEntityTrait;
Expand Down Expand Up @@ -100,6 +101,14 @@ public static function setup(EntityMetadata $metadata): void
//
}

#[BeforeStoreEvent]
public static function beforeStore(BeforeStoreEvent $event): void
{
$data = &$event->getData();

$data['language'] = $data['language'] ?? null ?: '*';
}

/**
* @inheritDoc
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Windwalker\ORM\Cast\JsonCast;
use Windwalker\ORM\EntityInterface;
use Windwalker\ORM\EntityTrait;
use Windwalker\ORM\Event\BeforeStoreEvent;
use Windwalker\ORM\Metadata\EntityMetadata;

/**
Expand Down Expand Up @@ -104,6 +105,14 @@ public static function setup(EntityMetadata $metadata): void
//
}

#[BeforeStoreEvent]
public static function beforeStore(BeforeStoreEvent $event): void
{
$data = &$event->getData();

$data['language'] = $data['language'] ?? null ?: '*';
}

public function getId(): ?int
{
return $this->id;
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Windwalker\ORM\EntityInterface;
use Windwalker\ORM\EntityTrait;
use Windwalker\ORM\Event\AfterDeleteEvent;
use Windwalker\ORM\Event\BeforeStoreEvent;
use Windwalker\ORM\Metadata\EntityMetadata;

/**
Expand Down Expand Up @@ -81,6 +82,14 @@ public static function setup(EntityMetadata $metadata): void
//
}

#[BeforeStoreEvent]
public static function beforeStore(BeforeStoreEvent $event): void
{
$data = &$event->getData();

$data['language'] = $data['language'] ?? null ?: '*';
}

#[AfterDeleteEvent]
public static function afterDelete(AfterDeleteEvent $event): void
{
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Windwalker\ORM\Cast\JsonCast;
use Windwalker\ORM\EntityInterface;
use Windwalker\ORM\EntityTrait;
use Windwalker\ORM\Event\BeforeStoreEvent;
use Windwalker\ORM\Metadata\EntityMetadata;

/**
Expand Down Expand Up @@ -89,6 +90,14 @@ public static function setup(EntityMetadata $metadata): void
//
}

#[BeforeStoreEvent]
public static function beforeStore(BeforeStoreEvent $event): void
{
$data = &$event->getData();

$data['language'] = $data['language'] ?? null ?: '*';
}

public function getId(): ?int
{
return $this->id;
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Front/Page/PageView.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function prepare(AppContext $app, View $view): array
$conditions = ['alias' => $path];

if ($this->isLocaleEnabled()) {
$conditions['language'] = $this->getLocale();
$conditions['language'] = [$this->getLocale(), '*'];
}

$page = $this->orm->mapper(Page::class)->mustFindOne($conditions);
Expand Down

0 comments on commit 579e35a

Please sign in to comment.