From: Vincent Vanwaelscappel Date: Fri, 2 Feb 2024 12:08:56 +0000 (+0100) Subject: wip #6693 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7d6b8ef1fffcd6c3b4663412ff8a537c7155ed7a;p=cubist_cms-back.git wip #6693 @2 --- diff --git a/src/app/Console/Commands/MenuGenerate.php b/src/app/Console/Commands/MenuGenerate.php index 8f84a11..657e916 100644 --- a/src/app/Console/Commands/MenuGenerate.php +++ b/src/app/Console/Commands/MenuGenerate.php @@ -11,7 +11,8 @@ class MenuGenerate extends CubistCommand public function handle() { - Artisan::call('config:cache'); + + $items = config('backpack.menu.items'); $res = ''; diff --git a/src/app/Console/Commands/OptimizeClearCommand.php b/src/app/Console/Commands/OptimizeClearCommand.php new file mode 100644 index 0000000..2c34c78 --- /dev/null +++ b/src/app/Console/Commands/OptimizeClearCommand.php @@ -0,0 +1,17 @@ + fn() => $this->callSilent('cubist:menu:generate') == 0, + ])->each(fn($task, $description) => $this->components->task($description, $task)); + + $this->newLine(); + } +} diff --git a/src/app/CubistBackpackServiceProvider.php b/src/app/CubistBackpackServiceProvider.php index 1e3e0fb..dd714d9 100644 --- a/src/app/CubistBackpackServiceProvider.php +++ b/src/app/CubistBackpackServiceProvider.php @@ -10,6 +10,7 @@ use Cubist\Backpack\Console\Commands\GenerateCommand; use Cubist\Backpack\Console\Commands\InstallCommand; use Cubist\Backpack\Console\Commands\LocaleCopy; use Cubist\Backpack\Console\Commands\LocaleSlugReset; +use Cubist\Backpack\Console\Commands\OptimizeClearCommand; use Cubist\Backpack\Console\Commands\PrecacheCommand; use Cubist\Backpack\Console\Commands\RefreshComposedAttributesCommand; use Cubist\Backpack\Console\Commands\SearchIndexCommand; @@ -90,8 +91,10 @@ class CubistBackpackServiceProvider extends ServiceProvider RefreshComposedAttributesCommand::class, SearchIndexCommand::class, LocaleCopy::class, - LocaleSlugReset::class + LocaleSlugReset::class, + OptimizeClearCommand::class, ]); + } public function provides() diff --git a/src/app/Magic/Fields/CMSTemplate.php b/src/app/Magic/Fields/CMSTemplate.php index 3c85211..b17cc30 100644 --- a/src/app/Magic/Fields/CMSTemplate.php +++ b/src/app/Magic/Fields/CMSTemplate.php @@ -13,15 +13,14 @@ class CMSTemplate extends SelectFromArray protected $_allowNull = false; protected $_translatable = false; - protected function _postSetAttributes() + public function getOptions() { - parent::_postSetAttributes(); $templates = TemplateAbstract::getTemplates(); $options = []; foreach ($templates as $name => $template) { $options[Str::snake($name)] = $template->getName(); } - $this->setAttribute('options', $options); + return $options; } } diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 5be3e00..c78da5e 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -80,7 +80,7 @@ class CMSPage extends CubistMagicNestedModel } - public function onCreating():bool + public function onCreating(): bool { $this->useTemplateIfNotSet(request('template')); return $this->onCreating(); @@ -99,13 +99,13 @@ class CMSPage extends CubistMagicNestedModel // parent::onBeforeEdit($controller, $id); // } - public function onSaving():bool + public function onSaving(): bool { $this->useTemplateIfNotSet(request('template')); return $this->onSaving(); } - public function onUpdating():bool + public function onUpdating(): bool { $this->useTemplateIfNotSet(request('template')); return $this->onUpdating(); @@ -197,14 +197,21 @@ class CMSPage extends CubistMagicNestedModel } } + public function create(array $attributes = []) { + if (!isset($attributes['template']) || !$attributes['template']) { + $attributes['template']='unset'; + } $this->useTemplate($attributes['template']); return parent::create($attributes); } public function update(array $attributes = [], array $options = []) { + if (!isset($attributes['template']) || !$attributes['template']) { + $attributes['template']='unset'; + } $this->useTemplate($attributes['template']); return parent::update($attributes, $options); } @@ -215,8 +222,7 @@ class CMSPage extends CubistMagicNestedModel $this->useTemplateIfNotSet($attributes['template']); } - $res = parent::setRawAttributes($attributes, $sync); - return $res; + return parent::setRawAttributes($attributes, $sync); } public static function getPagesList($variant = null) @@ -258,6 +264,6 @@ class CMSPage extends CubistMagicNestedModel if ($this instanceof CMSPage) { $this->useTemplate(); } - parent::copyTranslations($from, $to, $overwrite); // TODO: Change the autogenerated stub + parent::copyTranslations($from, $to, $overwrite); } } diff --git a/src/app/Magic/Models/CubistMagicPageModel.php b/src/app/Magic/Models/CubistMagicPageModel.php index cdd0f6c..a36b0d5 100644 --- a/src/app/Magic/Models/CubistMagicPageModel.php +++ b/src/app/Magic/Models/CubistMagicPageModel.php @@ -90,9 +90,9 @@ class CubistMagicPageModel extends CubistMagicTranslatableModel $this->addFieldAtEnd([ 'name' => 'meta_title', - 'label' => trans('backpack::pagemanager.meta_title'), + 'label' => 'Titre ', 'type' => 'Text', - 'hint' => 'Si vide, le titre court est utilisé' . ' ' . 'Longueur recommandée : 60 caractères', + 'hint' => 'Contenu de la balise <title>. Si vide, le titre court est utilisé' . ' ' . 'Longueur recommandée : 60 caractères', 'tab' => $tab, 'fake' => true, 'store_in' => 'seo', @@ -100,9 +100,9 @@ class CubistMagicPageModel extends CubistMagicTranslatableModel $this->addFieldAtEnd([ 'name' => 'meta_description', - 'label' => trans('backpack::pagemanager.meta_description'), + 'label' => 'Description', 'type' => 'Textarea', - 'hint' => 'Longueur recommandée : 160 caractères', + 'hint' => 'Contenu de <meta name="description">. Longueur recommandée : 160 caractères', 'tab' => $tab, 'fake' => true, 'store_in' => 'seo', @@ -115,6 +115,7 @@ class CubistMagicPageModel extends CubistMagicTranslatableModel 'default' => true, 'tab' => $tab, 'fake' => true, + 'translatable'=>false, 'store_in' => 'seo', ]); @@ -125,6 +126,7 @@ class CubistMagicPageModel extends CubistMagicTranslatableModel 'hint' => 'Liste des URL alternatives correspondant à cette page. Peut être utilisé lors de la migration. Si un visiteur tape une de ces URL, il sera redirigé vers cette page.', 'tab' => $tab, 'fake' => true, + 'translatable'=>false, 'store_in' => 'seo']); } diff --git a/src/app/Template/FirstRedirection.php b/src/app/Template/FirstRedirection.php index 2eaaa50..dbe504b 100644 --- a/src/app/Template/FirstRedirection.php +++ b/src/app/Template/FirstRedirection.php @@ -20,4 +20,9 @@ class FirstRedirection extends Redirection { } + + public function showInDropDown() + { + return true; + } } diff --git a/src/app/Template/InternalRedirection.php b/src/app/Template/InternalRedirection.php index 82de3a8..21a02da 100644 --- a/src/app/Template/InternalRedirection.php +++ b/src/app/Template/InternalRedirection.php @@ -22,4 +22,9 @@ class InternalRedirection extends Redirection ] ); } + + public function showInDropDown() + { + return true; + } } diff --git a/src/app/Template/Navigation.php b/src/app/Template/Navigation.php index ec367b6..33facbe 100644 --- a/src/app/Template/Navigation.php +++ b/src/app/Template/Navigation.php @@ -26,5 +26,9 @@ class Navigation extends TemplateAbstract return '* Navigation'; } + public function showInDropDown() + { + return true; + } } diff --git a/src/app/Template/Redirection.php b/src/app/Template/Redirection.php index 22ceed7..7b8ed8e 100644 --- a/src/app/Template/Redirection.php +++ b/src/app/Template/Redirection.php @@ -31,4 +31,9 @@ class Redirection extends TemplateAbstract { return '* Redirection externe'; } + + public function showInDropDown() + { + return true; + } } diff --git a/src/app/Template/TemplateAbstract.php b/src/app/Template/TemplateAbstract.php index 9737c10..ba73d58 100644 --- a/src/app/Template/TemplateAbstract.php +++ b/src/app/Template/TemplateAbstract.php @@ -97,11 +97,13 @@ class TemplateAbstract self::$_templates = []; $roots = [__DIR__ => 'Cubist\\Backpack\\Template', app_path() . '/Templates' => 'App\\Templates']; foreach ($roots as $templates_root => $prefix) { + if (!file_exists($templates_root)) { continue; } $dr = opendir($templates_root); while ($file = readdir($dr)) { + if ($file == '.' || $file == '..' || is_dir($templates_root . '/' . $file)) { continue; } diff --git a/src/app/Template/Undefined.php b/src/app/Template/Undefined.php new file mode 100644 index 0000000..c400dff --- /dev/null +++ b/src/app/Template/Undefined.php @@ -0,0 +1,11 @@ +checkIfFieldIsFirstOfItsType($field)) + + {{-- FIELD CSS - will be loaded in the after_styles section --}} @push('crud_fields_styles') - - - + {{-- include select2 css --}} + @basset('https://unpkg.com/select2@4.0.13/dist/css/select2.min.css') + @basset('https://unpkg.com/select2-bootstrap-theme@0.1.0-beta.10/dist/select2-bootstrap.min.css') @endpush {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') - - + {{-- include select2 js --}} + @basset('https://unpkg.com/select2@4.0.13/dist/js/select2.full.min.js') + @if (app()->getLocale() !== 'en') + @basset('https://unpkg.com/select2@4.0.13/dist/js/i18n/' . str_replace('_', '-', app()->getLocale()) . '.js') + @endif + @bassetBlock('backpack/pro/fields/select2-from-array-field.js') + @endBassetBlock @endpush - -@endif {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}