diff --git a/src/Module/Admin/Article/ArticleController.php b/src/Module/Admin/Article/ArticleController.php index a29f3878..41871191 100644 --- a/src/Module/Admin/Article/ArticleController.php +++ b/src/Module/Admin/Article/ArticleController.php @@ -12,6 +12,7 @@ use Lyrasoft\Luna\Services\TagService; use Unicorn\Controller\CrudController; use Unicorn\Controller\GridController; +use Unicorn\Repository\Event\PrepareSaveEvent; use Unicorn\Upload\FileUploadManager; use Unicorn\Upload\FileUploadService; use Windwalker\Core\Application\AppContext; @@ -41,6 +42,14 @@ public function save( ): mixed { $form = $app->make(EditForm::class); + $controller->prepareSave( + function (PrepareSaveEvent $event) use ($app) { + $data = &$event->getData(); + + $data['type'] = $app->input('type'); + } + ); + $controller->afterSave( function (AfterSaveEvent $event) use ($fileUploadService, $tagService, $repository, $app) { $data = $event->getData(); diff --git a/src/Module/Admin/Article/ArticleEditView.php b/src/Module/Admin/Article/ArticleEditView.php index b97e3077..bc1c96c5 100644 --- a/src/Module/Admin/Article/ArticleEditView.php +++ b/src/Module/Admin/Article/ArticleEditView.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Lyrasoft\Luna\Module\Admin\Article; +namespace App\Module\Admin\Article; use Lyrasoft\Luna\Entity\Article; use Lyrasoft\Luna\Entity\TagMap; @@ -10,7 +10,7 @@ use Lyrasoft\Luna\Field\LocaleSwitchField; use Lyrasoft\Luna\Locale\LanguageAssocTrait; use Lyrasoft\Luna\Locale\LocaleAwareTrait; -use Lyrasoft\Luna\Module\Admin\Article\Form\EditForm; +use App\Module\Admin\Article\Form\EditForm; use Lyrasoft\Luna\Repository\ArticleRepository; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Attributes\ViewModel; @@ -59,7 +59,7 @@ public function prepare(AppContext $app, View $view): mixed /** @var Article $item */ $item = $this->repository->getItem(compact('id')); - if ($type && $item->getType() !== $type) { + if ($type && $item && $item->getType() !== $type) { return $this->nav->self()->var('type', $item->getType()); } @@ -102,9 +102,20 @@ public function prepare(AppContext $app, View $view): mixed */ protected function prepareMetadata(AppContext $app, View $view): void { + $type = $app->input('type'); + + $langKey = "luna.$type.article.edit.title"; + $appLangKey = "app.$type.article.edit.title"; + + if ($this->lang->has($langKey)) { + $title = $this->trans($langKey); + } elseif ($this->lang->has($appLangKey)) { + $title = $this->trans($appLangKey); + } else { + $title = $this->trans('unicorn.title.edit', title: $this->trans('luna.article.title')); + } + $view->getHtmlFrame() - ->setTitle( - $this->trans('unicorn.title.edit', title: $this->trans('luna.article.title')) - ); + ->setTitle($title); } } diff --git a/src/Module/Admin/Article/ArticleListView.php b/src/Module/Admin/Article/ArticleListView.php index 96512baa..a90e8091 100644 --- a/src/Module/Admin/Article/ArticleListView.php +++ b/src/Module/Admin/Article/ArticleListView.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Lyrasoft\Luna\Module\Admin\Article; +namespace App\Module\Admin\Article; -use Lyrasoft\Luna\Module\Admin\Article\Form\GridForm; +use App\Module\Admin\Article\Form\GridForm; use Lyrasoft\Luna\Repository\ArticleRepository; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Attributes\ViewModel; @@ -63,6 +63,7 @@ public function prepare(AppContext $app, View $view): array $items = $this->repository->getListSelector() ->addFilters($filter) + ->where('article.type', $type) ->searchTextFor( $search['*'] ?? '', $this->getSearchFields() @@ -155,9 +156,19 @@ public function showFilterBar(array $filter): bool */ protected function prepareMetadata(AppContext $app, View $view): void { - $view->getHtmlFrame() - ->setTitle( - $this->trans('unicorn.title.grid', title: $this->trans('luna.article.title')) - ); + $type = $app->input('type'); + + $langKey = "luna.$type.article.list.title"; + $appLangKey = "app.$type.article.list.title"; + + if ($this->lang->has($langKey)) { + $title = $this->trans($langKey); + } elseif ($this->lang->has($appLangKey)) { + $title = $this->trans($appLangKey); + } else { + $title = $this->trans('unicorn.title.grid', title: $this->trans('luna.article.title')); + } + + $view->setTitle($title); } }