FEATURE: add language to content pages
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Models\Module;
|
|||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
class CreateNewContent extends Controller
|
class CreateNewContent extends Controller
|
||||||
@@ -56,7 +57,8 @@ class CreateNewContent extends Controller
|
|||||||
'templates' => $templates,
|
'templates' => $templates,
|
||||||
'moduleId' => $moduleId,
|
'moduleId' => $moduleId,
|
||||||
'page' => $this->content,
|
'page' => $this->content,
|
||||||
'rootPages' => $this->content->getOverview()->get(),
|
'rootPages' => $this->content->getOverview()
|
||||||
|
->get(),
|
||||||
'moduleName' => trans($module->name),
|
'moduleName' => trans($module->name),
|
||||||
'extraData' => call_user_func([$module->handler, 'loadExtraData'], $this->content),
|
'extraData' => call_user_func([$module->handler, 'loadExtraData'], $this->content),
|
||||||
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
|
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
|
||||||
@@ -86,6 +88,7 @@ class CreateNewContent extends Controller
|
|||||||
|
|
||||||
// setup basic info
|
// setup basic info
|
||||||
$page->user_id = \Auth::user()->id;
|
$page->user_id = \Auth::user()->id;
|
||||||
|
$page->language = LaravelLocalization::getLocale();
|
||||||
$page->title = $request->title;
|
$page->title = $request->title;
|
||||||
$page->url = Str::slug($request->url);
|
$page->url = Str::slug($request->url);
|
||||||
$page->published_from = $request->publishedFrom;
|
$page->published_from = $request->publishedFrom;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use App\Models\File;
|
|||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
class EditContent extends Controller
|
class EditContent extends Controller
|
||||||
@@ -274,6 +275,7 @@ class EditContent extends Controller
|
|||||||
|
|
||||||
// disable any other existing homepage
|
// disable any other existing homepage
|
||||||
Content::where('is_homepage', 1)
|
Content::where('is_homepage', 1)
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->update(['is_homepage' => 0]);
|
->update(['is_homepage' => 0]);
|
||||||
|
|
||||||
// set new homepage
|
// set new homepage
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use App\Enumerations\ContentStatuses;
|
use App\Enumerations\ContentStatuses;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Content
|
* Class Content
|
||||||
@@ -15,6 +16,7 @@ class Content extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
'parent_id',
|
'parent_id',
|
||||||
|
'language',
|
||||||
'module_handler',
|
'module_handler',
|
||||||
'published_from',
|
'published_from',
|
||||||
'published_to',
|
'published_to',
|
||||||
@@ -53,6 +55,7 @@ class Content extends Model
|
|||||||
public function getHomepage()
|
public function getHomepage()
|
||||||
{
|
{
|
||||||
return $this->getPageQuery()
|
return $this->getPageQuery()
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->where('is_homepage', 1)
|
->where('is_homepage', 1)
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
@@ -68,6 +71,7 @@ class Content extends Model
|
|||||||
{
|
{
|
||||||
return $this->getPageQuery()
|
return $this->getPageQuery()
|
||||||
->where('url', $url)
|
->where('url', $url)
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +85,7 @@ class Content extends Model
|
|||||||
if (!$this->subpagesInit) {
|
if (!$this->subpagesInit) {
|
||||||
$this->subpages = $this->getPageQuery()
|
$this->subpages = $this->getPageQuery()
|
||||||
->where('parent_id', $this->id)
|
->where('parent_id', $this->id)
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// convert JSON settings into stdClass
|
// convert JSON settings into stdClass
|
||||||
@@ -142,6 +147,7 @@ class Content extends Model
|
|||||||
public function rootPages()
|
public function rootPages()
|
||||||
{
|
{
|
||||||
$rootPages = $this->getPageQuery()
|
$rootPages = $this->getPageQuery()
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->where('parent_id', null);
|
->where('parent_id', null);
|
||||||
|
|
||||||
if ($this->id) {
|
if ($this->id) {
|
||||||
@@ -166,6 +172,7 @@ class Content extends Model
|
|||||||
$query = DB::table('contents')
|
$query = DB::table('contents')
|
||||||
->select('contents.*', 'modules.name AS module_name')
|
->select('contents.*', 'modules.name AS module_name')
|
||||||
->where('contents.status', '<>', self::STATUS_DELETED)
|
->where('contents.status', '<>', self::STATUS_DELETED)
|
||||||
|
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
||||||
->join('modules', 'modules.handler', '=', 'contents.module_handler')
|
->join('modules', 'modules.handler', '=', 'contents.module_handler')
|
||||||
->orderBy('created_at', 'DESC');
|
->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<?php namespace App\Providers;
|
<?php namespace App\Providers;
|
||||||
|
|
||||||
use App\Models\File;
|
|
||||||
use App\Models\Language;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
@@ -12,9 +10,16 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
|
|
||||||
$languages = DB::table('languages')->get();
|
$languages = DB::table('languages')
|
||||||
|
->get();
|
||||||
|
|
||||||
$supportedLocales = ['en' => ['native' => 'English', 'script' => 'Latn', 'name' => 'common.lang.english']];
|
$supportedLocales = [
|
||||||
|
config('app.locale') => [
|
||||||
|
'native' => env('LOCALE_NATIVE_NAME'),
|
||||||
|
'script' => env('LOCALE_SCRIPT'),
|
||||||
|
'name' => env('LOCALE_TRANSLATED_NAME'),
|
||||||
|
]
|
||||||
|
];
|
||||||
foreach ($languages as $language) {
|
foreach ($languages as $language) {
|
||||||
$supportedLocales[$language->code] = [
|
$supportedLocales[$language->code] = [
|
||||||
'native' => $language->native,
|
'native' => $language->native,
|
||||||
@@ -30,7 +35,8 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot() {
|
public function boot()
|
||||||
\App::setLocale(LaravelLocalization::setLocale());
|
{
|
||||||
|
\App::setLocale(LaravelLocalization::getCurrentLocale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -59,7 +59,7 @@ return [
|
|||||||
'username' => env('DB_USERNAME', 'forge'),
|
'username' => env('DB_USERNAME', 'forge'),
|
||||||
'password' => env('DB_PASSWORD', ''),
|
'password' => env('DB_PASSWORD', ''),
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'collation' => 'utf8_unicode_ci',
|
'collation' => 'utf8_general_ci',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'strict' => false,
|
'strict' => false,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddLanguageToContentPages extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$platform = Schema::getConnection()
|
||||||
|
->getDoctrineSchemaManager()
|
||||||
|
->getDatabasePlatform();
|
||||||
|
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
|
||||||
|
DB::raw('ALTER TABLE `languages`
|
||||||
|
CHANGE `code` `code` varchar(8) COLLATE \'utf8_general_ci\' NOT NULL FIRST,
|
||||||
|
CHANGE `name` `name` varchar(255) COLLATE \'utf8_general_ci\' NOT NULL COMMENT \'Translated name for given language\' AFTER `code`,
|
||||||
|
CHANGE `script` `script` varchar(16) COLLATE \'utf8_general_ci\' NOT NULL DEFAULT \'Latn\' COMMENT \'ISO code for locale script (Latn, Arab, ...)\' AFTER `name`,
|
||||||
|
CHANGE `native` `native` varchar(255) COLLATE \'utf8_general_ci\' NOT NULL COMMENT \'Native name for language\' AFTER `script`,
|
||||||
|
COLLATE \'utf8_general_ci\';');
|
||||||
|
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->string('language', 8)
|
||||||
|
->after('template')
|
||||||
|
->default(\App::getLocale());
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->index('language')
|
||||||
|
->change();
|
||||||
|
|
||||||
|
$table->unique(['language', 'url']);
|
||||||
|
|
||||||
|
$doctrine = Schema::getConnection()
|
||||||
|
->getDoctrineSchemaManager()
|
||||||
|
->listTableDetails('contents');
|
||||||
|
|
||||||
|
// remove unique index from URL column
|
||||||
|
if ($doctrine->hasIndex('url_UNIQUE')) {
|
||||||
|
$table->dropUnique('url_UNIQUE');
|
||||||
|
} else {
|
||||||
|
$table->dropUnique('contents_url_unique');
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->foreign('language')
|
||||||
|
->references('code')
|
||||||
|
->on('languages')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->dropForeign('contents_language_foreign');
|
||||||
|
$table->dropIndex('contents_language_index');
|
||||||
|
$table->dropUnique('contents_language_url_unique');
|
||||||
|
$table->dropColumn('language');
|
||||||
|
$table->unique('url');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user