Skip to content

Commit

Permalink
LandingPage [WEB-2982]
Browse files Browse the repository at this point in the history
I started with the landing pages because it seemed
straightforward with minimal columns. I found that we'll have to
create a `setUpController` method and replace a few static
variables with setters.
  • Loading branch information
zachgarwood committed Jan 21, 2025
1 parent e489ecc commit fd5e715
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
44 changes: 22 additions & 22 deletions app/Http/Controllers/Twill/LandingPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,20 @@
namespace App\Http\Controllers\Twill;

use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\TableColumns;
use App\Http\Controllers\LandingPagesController;
use App\Models\LandingPage;
use App\Repositories\LandingPageRepository;

class LandingPageController extends \App\Http\Controllers\Twill\ModuleController
class LandingPageController extends BaseController
{
protected $moduleName = 'landingPages';

protected $indexColumns = [
'title' => [
'title' => 'Title',
'edit_link' => true,
'sort' => true,
'field' => 'title',
],
'type' => [
'title' => 'Type',
'field' => 'type',
],
];

protected $indexWith = [];

protected $defaultOrders = [];

protected $previewView = 'site.landingPageDetail';
protected function setUpController(): void
{
parent::setUpController();
$this->setModuleName('landingPages');
$this->setPreviewView('site.landingPageDetail');
}

/**
* Dynamically set the view prefix to include the landing page type.
Expand All @@ -37,7 +25,7 @@ public function edit(TwillModelContract|int $id, $submoduleId = null): mixed
{
$landingPage = $this->repository->getById($id);
$prefix = str($landingPage->type)->camel();
$this->viewPrefix = "admin.$this->moduleName.$prefix";
$this->viewPrefix = config('twill.admin_route_name_prefix') . "$this->moduleName.$prefix";
return parent::edit($id, $submoduleId);
}

Expand All @@ -51,6 +39,18 @@ protected function indexData($request)
];
}

protected function additionalIndexTableColumns(): TableColumns
{
$columns = TableColumns::make();
$columns->add(
Text::make()
->field('type')
->optional()
);

return $columns;
}

protected function formData($request)
{
$types = collect(LandingPage::TYPES);
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Twill/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

class ModuleController extends BaseModuleController
{

protected function setPreviewView(string $previewView): void
{
$this->previewView = $previewView;
}

protected function previewData($item)
{
return [
Expand Down

0 comments on commit fd5e715

Please sign in to comment.