Skip to content

Commit

Permalink
feat: add controller column to cms_template (#207)
Browse files Browse the repository at this point in the history
Co-authored-by: Thessa Kockelkorn <thessa@notfound.nl>
  • Loading branch information
thessakockelkorn and Thessa Kockelkorn committed Feb 15, 2024
1 parent 967213f commit 49288b5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
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

0 comments on commit 49288b5

Please sign in to comment.