From 500d7878116b793b4ec5957bca8da0f1dd6ef16b Mon Sep 17 00:00:00 2001 From: "stephen@cubedesigners.com" Date: Thu, 14 May 2020 11:17:04 +0000 Subject: [PATCH] WIP #3641 @3.75 --- framework/application/Bootstrap.php | 7 ++- .../controllers/BlogpostController.php | 2 +- .../forms/CMS/Sub/Blog/ContentBlock.php | 39 ++++++++++++++++ .../forms/CMS/Sub/Blog/ContentBlocks.php | 14 ++++++ .../application/forms/CMS/Sub/Blog/Post.php | 11 +++-- .../application/views/helpers/BlogIndex.php | 3 +- js/010-admin.js | 45 ++++++++++++++++++- 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 framework/application/forms/CMS/Sub/Blog/ContentBlock.php create mode 100644 framework/application/forms/CMS/Sub/Blog/ContentBlocks.php diff --git a/framework/application/Bootstrap.php b/framework/application/Bootstrap.php index ebb08cd..d826599 100644 --- a/framework/application/Bootstrap.php +++ b/framework/application/Bootstrap.php @@ -57,8 +57,13 @@ class Bootstrap extends CubeIT_Bootstrap { while ($r = $q->fetch()) { - $online = true; + $r = CubeIT_Util_Cms::unserialize($r, $locale); + $pageTitle = $r->title; + if (empty($pageTitle)) continue; + + $online = boolval($r->online); + if (!$online && !$isAdmin) continue; $p = new CubeIT_Navigation_Page_Locale(); $p->setController('Blogpost'); diff --git a/framework/application/controllers/BlogpostController.php b/framework/application/controllers/BlogpostController.php index dcb2f79..cd32ce2 100644 --- a/framework/application/controllers/BlogpostController.php +++ b/framework/application/controllers/BlogpostController.php @@ -25,7 +25,7 @@ class BlogpostController extends CubeIT_Controller_PageController { // Get the first and only array item $post = reset($post); - $this->view->post = $post; + $this->view->post = $post->unserialize(); $this->view->headTitle($post->getTitle(), 'SET'); } diff --git a/framework/application/forms/CMS/Sub/Blog/ContentBlock.php b/framework/application/forms/CMS/Sub/Blog/ContentBlock.php new file mode 100644 index 0000000..50d5a53 --- /dev/null +++ b/framework/application/forms/CMS/Sub/Blog/ContentBlock.php @@ -0,0 +1,39 @@ +setAttrib('data-name', 'content-type') + ->setMultiOptions([ + 'text' => 'Text Block', + 'image' => 'Image', + ]); + $this->addElement($select); + + $text = new CubeIT_Form_Element_Markitup_Basic('text'); + $text->setLabel('Text Block') + ->setAttrib('data-type', 'text'); // Shown when "text" content type is selected + $this->addElementLocalized($text, $compact_translations); + + $image = new CubeIT_Form_Element_File_Image('image'); + $image->setLabel('Image') + ->setMaxItems(1) + ->setAttrib('data-type', 'image'); // Shown when "image" content type is selected + $this->addElementLocalized($image, $compact_translations); + + $image_style = new Zend_Form_Element_Select('image_style'); + $image_style->setLabel('Image Style') + ->setAttrib('data-type', 'image') + ->setMultiOptions([ + '' => 'Normal', + 'xl' => 'Extra Large', + ]); + $this->addElementLocalized($image_style, $compact_translations); + + } +} diff --git a/framework/application/forms/CMS/Sub/Blog/ContentBlocks.php b/framework/application/forms/CMS/Sub/Blog/ContentBlocks.php new file mode 100644 index 0000000..29460f1 --- /dev/null +++ b/framework/application/forms/CMS/Sub/Blog/ContentBlocks.php @@ -0,0 +1,14 @@ +setBaseSubForm($block); + $this->setBaseLegend('Content block'); + $this->setNewLegend('New content block'); + } + +} diff --git a/framework/application/forms/CMS/Sub/Blog/Post.php b/framework/application/forms/CMS/Sub/Blog/Post.php index 0fa5f96..34ccdc5 100644 --- a/framework/application/forms/CMS/Sub/Blog/Post.php +++ b/framework/application/forms/CMS/Sub/Blog/Post.php @@ -6,6 +6,8 @@ class Fluidbook_Form_CMS_Sub_Blog_Post extends CubeIT_Form_List_Model public function init() { parent::init(); + $compact_translations = false; + $id = new CubeIT_Form_Element_Id(); $this->addElement($id); @@ -22,17 +24,20 @@ class Fluidbook_Form_CMS_Sub_Blog_Post extends CubeIT_Form_List_Model $title = new CubeIT_Form_Element_Text('title'); $title->setLabel(__('Post Title')); - $this->addElement($title); + $this->addElementLocalized($title, $compact_translations); $excerpt = new CubeIT_Form_Element_Markitup('excerpt'); $excerpt->setLabel(__('Excerpt')); - $this->addElement($excerpt); + $this->addElementLocalized($excerpt, $compact_translations); $thumbnail = new CubeIT_Form_Element_File_Image('thumbnail'); $thumbnail->setLabel(__('Post Thumbnail')); + $thumbnail->setMaxItems(1); $this->addElement($thumbnail); - // TODO add content blocks (text + images) based on Cubedesigners case studies content. Also add author reference. + $content = new Fluidbook_Form_CMS_Sub_Blog_ContentBlocks(); + $content->setLegend('Content Blocks'); + $this->addSubForm($content, 'content'); $this->setListTitle(__('Blog Posts')); $this->setNewTitle(__('New Post')); diff --git a/framework/application/views/helpers/BlogIndex.php b/framework/application/views/helpers/BlogIndex.php index 383d64c..203100e 100644 --- a/framework/application/views/helpers/BlogIndex.php +++ b/framework/application/views/helpers/BlogIndex.php @@ -11,7 +11,8 @@ class Fluidbook_View_Helper_BlogIndex extends CubeIT_View_Helper_Abstract { $res = ''; foreach ($posts as $post) { - $res .= $this->post($post); + /* @var $post Fluidbook_Model_Blog */ + $res .= $this->post($post->unserialize()); } return $this->htmlElement($res, 'div', ['class' => 'blog-index']); diff --git a/js/010-admin.js b/js/010-admin.js index c898d29..2dee9c4 100644 --- a/js/010-admin.js +++ b/js/010-admin.js @@ -1 +1,44 @@ -// Todo: adapt code from cubedesigners-v6/js/admin.js to have the custom multi-subform with different fields shown / hidden depending on the option selected +TO_LOAD[TO_LOAD.length] = 'load_admin();'; + +function load_admin() { + initContentBlocks(); +} + +// Toggle visibility of fields depending on the content type in the repeater +function initContentBlocks() { + $('select[data-name="content-type"]').each(function() { + var target = $(this).closest('fieldset'); + displayFormTypeElements(target, this.value); + }); + + $(document).on('change', 'select[data-name="content-type"]', function() { + var target = $(this).closest('fieldset'); + displayFormTypeElements(target, this.value); + }); +} + +function displayFormTypeElements(target, type) { + + target.find('.legend').text('Content Block (' + type + ')'); + + // First hide all fields + target.find('[data-type]').each(function() { + getFieldWrapper($(this)).hide(); + }); + + // Now show just the relevant fields + target.find('[data-type="'+ type +'"]').each(function() { + getFieldWrapper($(this)).show(); + }); + + +} + +function getFieldWrapper(field) { + // The structure of the fields is different depending on whether or not it is localised + if (field.parents('.localized').length > 0) { + return field.parents('.localized').parent(); + } else { + return field.parents('.elementwrap').parent(); + } +} -- 2.39.5