Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add controller column to cms_template #207

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('cms_template', function (Blueprint $table) {
$table->string('controller')->after('filename')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('cms_template', function (Blueprint $table) {
$table->dropColumn('controller');
});
}
};
6 changes: 4 additions & 2 deletions src/Models/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ class Template extends AssetModel
'properties',
'name',
'filename',
'controller',
];

protected $fillable = [
'name',
'filename',
'controller',
'enabled',
'params',
'allow_children',
Expand All @@ -86,11 +88,11 @@ public function items()

public function getIdentifier()
{
return strtolower($this->attributes['filename']);
return strtolower($this->attributes['controller'] ?? $this->attributes['filename']);
}

private function getSiteTableName()
{
return strtolower($this->filename);
return strtolower($this->controller ?? $this->filename);
}
}
19 changes: 15 additions & 4 deletions src/Services/Indexer/IndexBuilderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ private function updatePage($menu, $lang)
// continue with customValues
$customValues = [];

$class = $menu->template->filename ?? '';
$className = 'App\Http\Controllers\Page\\'.$class.'Controller';
$className = 'App\Http\Controllers\Page\\'.$this->controllerName($menu).'Controller';

$c = null;
$priority = 1;
$solrDate = '';
Expand Down Expand Up @@ -198,8 +198,7 @@ private function updatePage($menu, $lang)

private function updateSubPages($menu, $lang)
{
$class = $menu->template->filename ?? '';
$className = 'App\Http\Controllers\Page\\'.$class.'Controller';
$className = 'App\Http\Controllers\Page\\'.$this->controllerName($menu).'Controller';
$c = null;
// update subPage if necessary

Expand All @@ -209,6 +208,18 @@ private function updateSubPages($menu, $lang)
}
}

private function controllerName($menu): string
{
$class = str_replace('/', '\\', $menu->template->getIdentifier() ?? '');
$classes = explode('\\', $class);
foreach ($classes as &$c) {

$c = ucfirst($c);
}

return implode('\\', $classes);
}

private function updateSubitems($class, $lang)
{
app()->setLocale($lang->url);
Expand Down
2 changes: 1 addition & 1 deletion src/Services/PageRouterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function getControllerClassName(Menu $page): string|false
return false;
}

$pageClassName = sprintf('App\\Http\\Controllers\\Page\\%sController', ucfirst($page->template->filename));
$pageClassName = sprintf('App\\Http\\Controllers\\Page\\%sController', ucfirst($page->template->controller ?? $page->template->filename));

if (class_exists($pageClassName)) {
return $pageClassName;
Expand Down
Loading