SFC block in Composer

Permalink Browser Info Environment
Hi Jordan,

I want to create a Composer page with a SFC block in it. (The idea is to offer a quick way to create galleries).
But it gives me an error in the Composer page (it works in the classical view):
***********
Warning: Invalid argument supplied for foreach() in /.../sortable_fancybox_gallery/view.php on line x
***********
It's at the :"foreach ($images as $img){"

Thank you in advance for you feedback
marc

Type: Discussion
Status: New
marcsublet
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
Hi Marc,
I just tested this out and was able to recreate the problem you're having. It appears that C5 does weird things which I don't entirely understand when it displays these blocks in the composer interface (and of course it's not documented anywhere so I don't really know how to find out the "right way" to fix it).

For now, you can patch the following file:
/packages/sortable_fancybox_gallery/blocks/sortable_fancybox_gallery/controller.php

...add a new function inside that class, above the existing "public function view() {" line:
public function composer() {
    $this->view();
}


This prevents the error from coming up, but doesn't look perfect. It's the best I can do for now. I'll post a message to the core team asking them if they can explain this, but I have not had a lot of luck getting technical answers from them on new features so don't hold your breath.

-Jordan
marcsublet replied on at Permalink Reply
marcsublet
Hi Jordan,

Thank you for your quick as Lucky Luck answer! Your workaround do the trick.
I like C5 but it's clear that the lack of good documentation is the biggest weakness of the tool.
The community is lucky to have good and available developers like you!

Best regards,
marc
marcsublet replied on at Permalink Reply
marcsublet
Hi Jordan,

I have pimped a little your code to add the ability to customize the render of the composer view like that:

// in controller
public function composer() {
   $this->view();
   $html = Loader::helper('html');            
   $bv = new BlockView();
   $bv->setBlockObject($this->getBlockObject());
   $css_composer = $html->css($bv->getBlockURL() . '/view_composer.css');
   $this->set('css_composer', $css_composer->file);
}


and in the template I have added the same method you use to load the css in isEditMode:

if($css_composer){
   ?>
   <script>
      $.ajax({
         url: '<?php  echo $css_composer; ?>',
         success: function(css) {
            css = '<style>' + css + '</style>';
            $('head').append(css);
         }
      });
   </script>
   <?php   
}
jordanlev replied on at Permalink Reply
jordanlev
Hi Marc,
Thanks for posting your better solution -- I'll try to include this in a future update of the addon.

Note that I think you can make your code even simpler by using Concrete5's built-in "addHeaderItem" javascript function, like so:
<?php if ($css_composer): ?>
<script>addHeaderItem('<?php echo $css_composer; ?>');</script>
<?php endif; ?>
marcsublet replied on at Permalink Reply
marcsublet
Thanks for your support.
marc
jamesleech replied on at Permalink Reply
jamesleech
Hi marc,

I am interested in your use of SFG a composer page.

Was SFG just showing a common set, that then displayed updated images which were added via composer OR were you able to only display images added through that unique page entry?

If so - how did you:
a) get the new images added to a unique set
b) tell SFG the name for that set to display only those images?


I am trying to create a composer page which allows my client to create an exhibition page and include a range of images relevant to only that event.

Cheerio,

James
marcsublet replied on at Permalink Reply
marcsublet
Hi James,

SFG is a very good tool but on more recent project I have worked in a different way:
I only use the "Fileset" attribute (free -http://www.concrete5.org/marketplace/addons/fileset-attribute/)... to display a gallery.
Then you can add the default value (= a global fileset) in your page type but not include it in the composer.
Step 2 is to add a custom attribute to the files (a select with the possibility for the users to add items)
Then when your user creates an "event" page he has a field to enter the "id" of the event.
In your template you can hardcode the display of all the files of the global fileset but with a filter on the custom attribute.

To display pictures based on a file set (You have to add the filter for the custom attributes)

<?php
$sID = $c->getCollectionAttributeValue('my_fileset_attribute');
if($sID > 0){
$fs = FileSet::getByID($sID);
$fl = new FileList();
$fl->filterBySet($fs);
$fl->sortByFileSetDisplayOrder($gs);
$files = $fl->get();
foreach($files as $f) {
$img = $ih->getThumbnail($f, 400, 400, true);
$fv = $f->getRecentVersion();
$title = htmlspecialchars($fv->getTitle(), ENT_QUOTES, 'UTF-8');
echo '<img src="'.$img->src.'" width="'.$img->width.'" height="'.$img->height.'" alt="'.$title.'" />';
}
}
?>

Regards,
marc
jordanlev replied on at Permalink Reply
jordanlev
I agree that this is a great technique, and I use it myself sometimes.

Thanks for posting this explanation and the code.

One quick little note: you can get rid of the $fv = $f->getRecentVersion() line of code and then change $fv->getTitle() to $f->getTitle(). Same result, just saves you one line of code.
jamesleech replied on at Permalink Reply
jamesleech
Lots to learn! Thanks guys

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.