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');
// 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');
}
--- /dev/null
+<?php
+
+class Fluidbook_Form_CMS_Sub_Blog_ContentBlock extends CubeIT_Form_SubForm {
+
+ public function init() {
+ parent::init();
+
+ $compact_translations = false;
+
+ $select = new Zend_Form_Element_Select('content_type');
+ $select->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);
+
+ }
+}
--- /dev/null
+<?php
+
+class Fluidbook_Form_CMS_Sub_Blog_ContentBlocks extends CubeIT_Form_Multi_SubForm {
+
+ public function init() {
+ parent::init();
+
+ $block = new Fluidbook_Form_CMS_Sub_Blog_ContentBlock();
+ $this->setBaseSubForm($block);
+ $this->setBaseLegend('Content block');
+ $this->setNewLegend('New content block');
+ }
+
+}
public function init() {
parent::init();
+ $compact_translations = false;
+
$id = new CubeIT_Form_Element_Id();
$this->addElement($id);
$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'));
$res = '';\r
\r
foreach ($posts as $post) {\r
- $res .= $this->post($post);\r
+ /* @var $post Fluidbook_Model_Blog */\r
+ $res .= $this->post($post->unserialize());\r
}\r
\r
return $this->htmlElement($res, 'div', ['class' => 'blog-index']);\r
-// 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();
+ }
+}