From: Vincent Vanwaelscappel Date: Fri, 15 Mar 2019 15:00:31 +0000 (+0100) Subject: wip #2628 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=8273ed9563659d6cc816178bb6ed101358108ef1;p=cubist_cms-back.git wip #2628 @4 --- diff --git a/src/app/Http/Controllers/CubistPageCrudController.php b/src/app/Http/Controllers/CubistPageCrudController.php new file mode 100644 index 0000000..28e167c --- /dev/null +++ b/src/app/Http/Controllers/CubistPageCrudController.php @@ -0,0 +1,108 @@ +getTemplates(); + + // set the default template + if ($template_name == false) { + $template_name = $templates[0]->getSlug(); + } + // actually use the template + if ($template_name) { + foreach ($templates as $template) { + if ($template->getSlug() == $template_name) { + $template->use($this->crud); + } + } + } + } + + // ----------------------------------------------- + // Methods that are particular to the PageManager. + // ----------------------------------------------- + + /** + * Populate the create/update forms with basic fields, that all pages need. + * + * @param string $template The name of the template that should be used in the current form. + */ + public function addDefaultPageFields($template = false) + { + $this->crud->addField([ + 'name' => 'template', + 'label' => trans('backpack::pagemanager.template'), + 'type' => 'select_page_template', + 'view_namespace' => 'pagemanager::fields', + 'options' => $this->getTemplatesArray(), + 'value' => $template, + 'allows_null' => false, + 'wrapperAttributes' => [ + 'class' => 'form-group col-md-6', + ], + 'tab' => 'General', + ]); + } + + + /** + * Get all defined template as an array. + * + * Used to populate the template dropdown in the create/update forms. + */ + public function getTemplatesArray() + { + $templates_array = []; + + $templates = $this->getTemplates(); + foreach ($templates as $template) { + if ($template->showInDropDown()) { + $slug = $template->getSlug(); + $name = $template->getName(); + $templates_array[$slug] = str_replace('_', ' ', Str::title($name)); + } + } + + return $templates_array; + } +} diff --git a/src/app/Template/Abstract.php b/src/app/Template/Abstract.php deleted file mode 100644 index b904264..0000000 --- a/src/app/Template/Abstract.php +++ /dev/null @@ -1,22 +0,0 @@ -crud = app()->get('crud'); - } - - public function addField($field) - { - } -} diff --git a/src/app/Template/TemplateAbstract.php b/src/app/Template/TemplateAbstract.php new file mode 100644 index 0000000..b862b24 --- /dev/null +++ b/src/app/Template/TemplateAbstract.php @@ -0,0 +1,136 @@ +crud = $crud; + $this->init(); + } + + protected function _seo() + { + $this->addField([ + 'name' => 'meta_title', + 'label' => trans('backpack::pagemanager.meta_title'), + 'type' => 'text', + 'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'), + 'tab' => 'Meta // SEO', + ]); + $this->addField([ + 'name' => 'meta_description', + 'label' => trans('backpack::pagemanager.meta_description'), + 'type' => 'textarea', + 'hint' => __('Recommended length: 160 chars'), + 'tab' => 'Meta // SEO', + ]); + $this->addField([ + 'name' => 'robots', + 'label' => __('Allow page index by search engines'), + 'type' => 'checkbox', + 'default' => true, + 'tab' => 'Meta // SEO', + ]); + } + + public function init() + { + + + $this->_common(); + } + + protected function _common() + { + $this->addField([ + 'name' => 'name', + 'label' => trans('backpack::pagemanager.page_name'), + 'type' => 'text', + 'wrapperAttributes' => [ + 'class' => 'form-group col-md-6', + ], + 'fake' => false, + 'tab' => 'General', + // 'disabled' => 'disabled' + ]); + $this->addField([ + 'name' => 'title', + 'label' => trans('backpack::pagemanager.page_title'), + 'type' => 'text', + 'fake' => false, + 'tab' => 'General', + // 'disabled' => 'disabled' + ]); + $this->addField([ + 'name' => 'slug', + 'label' => trans('backpack::pagemanager.page_slug'), + 'type' => 'text', + 'hint' => trans('backpack::pagemanager.page_slug_hint'), + 'fake' => false, + 'tab' => 'General', + // 'disabled' => 'disabled' + ]); + + $this->addField([ + 'name' => 'status', + 'type' => 'select_from_array', + 'default' => '0', + 'label' => __('Status'), + 'options' => ['0' => __('Offline'), '1' => __('Published')], + 'tab' => 'General', + ]); + $this->_seo(); + } + + + public function showInDropDown() + { + return false; + } + + public function getName() + { + return static::class; + } + + public function getSlug() + { + $path = explode('\\', static::class); + $class = array_pop($path); + + return Str::slug($class); + } + + /** + * Add a field to the create/update form or both. + * + * @param string|array $field The new field. + * @param string $form The CRUD form. Can be 'create', 'update' or 'both'. Default is 'both'. + * + * @return CrudPanel + */ + public function addField($field, $form = 'both') + { + // Set default options of field + $defaults = ['tab' => 'Contents', + 'fake' => true, + 'store_in' => 'extras']; + $field = array_merge($defaults, $field); + + + return $this->crud->addField($field, $form); + } +}