Skip to content

Commit

Permalink
Fix article type edit
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Jan 19, 2024
1 parent 2413a96 commit 1bc83cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/Module/Admin/Article/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
23 changes: 17 additions & 6 deletions src/Module/Admin/Article/ArticleEditView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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;
use Lyrasoft\Luna\Field\ArticleModalField;
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;
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
}
}
23 changes: 17 additions & 6 deletions src/Module/Admin/Article/ArticleListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1bc83cb

Please sign in to comment.