Enabling Composer Editing for Thumb Gallery Add-On

Permalink
Hi folks,

I'm using C5.7.4RC2 and Vivid's Thumb Gallery. I'd like to add a gallery block to a page template of a page type. On page creation in composer I want to select a fileset, see the thumbnails of the selected fileset and reorganize the thumbnails display order.

So far I've made some progress and created a mostly working composer.php residing in /packages/vivid_thumb_gallery/blocks/vivid_thumb_gallery/composer.php
<?php    
defined('C5_EXECUTE') or die(_("Access Denied."));
/***
*   replaced all hard-coded form names with $view->field() 
*   replaced deprecated Loader::helper with Core::make
***/
// adding helpers
$al = Core::make('helper/concrete/asset_library');
$uh = Core::make('helper/concrete/urls');
$bt = BlockType::getByHandle('vivid_thumb_gallery');
// setting tools URL
$toolsURL = $uh->getBlockTypeToolsURL($bt);
$this->controller->set("toolsURL",$toolsURL."/get_thumbs");
$toolsURL = $toolsURL."/get_thumbs";
?>


So far fileset selection and thumbnail display work fine in composer. Clicking "Save and Exit", "Edit Mode" and "Publish" saves everything, except the thumbs display order.

Now I'm stabing in the dark. Can anyone tell me why the display order is not saved? Any hint pointing me into the right direction is much appreciated.

I've already posted a support request, but now I'm so close to success that I thought this might help others and get's more attention in the forum. Forgive me please for cross posting.

Thank you in advance.

HardOne
 
razorcommerce replied on at Permalink Reply
razorcommerce
Fairly wild guess here because I've never seen that package so I don't know how it works. What I'd be aiming to do though is find the logic used to control display order in the normal interface. It might involve an ajax call? So use the regular interface, watch for that ajax call and see what is passed. Maybe the current order is stored in some element then passed. Again just a guess not being able to see the original but I might suggest you post some relevant parts of the controller if you want more help because at some point the display order has to be saved through a method in the controller.
HardOne replied on at Permalink Reply
HardOne
Thank you very much much for your response.

I've tried to get behind the logic but I got it only half way. The display order is stored via controllers save() method into its own table. With $bID stored against $fID and an integer value for the display order. But I see nothing creating that array to pass it over to the save method. Neither in form.php, nor somewhere else. In form.php it must be because it's working via edit block.

What I can see is, that submitting composer form does not run save() function from controller.php. As I've read in the docs submitting a form to the backend should run save() method. I have no idea why it's not working in this case.

I've never learned js/ajax/json. Seems like an epic fail from me. There is an ajax call to get the thumbnails in add/edit form, but I can't find something ajax related storing data into the database.
I'll have to dig deeper into this, but I feel I need some more help.

For reference here's the controller.php
<?php 
namespace Concrete\Package\VividThumbGallery\Block\VividThumbGallery;
use \Concrete\Core\Block\BlockController;
use Loader;
use \File;
use FileSet;
use FileList;
use BlockType;
use Page;
use Core;
use \Concrete\Core\Block\View\BlockView as BlockView;
use Concrete\Core\File\Type\Type as FileType;
defined('C5_EXECUTE') or die(_("Access Denied.")); 
class Controller extends BlockController
{


and the form.php (add.php and edit.php simply include form.php)
<?php    
defined('C5_EXECUTE') or die(_("Access Denied."));
$al = Loader::helper('concrete/asset_library');
?>
<style>
    #btn-launch-file-manager { margin-top: 23px; }
    .thumb-item-shell { border: 1px solid #fff; box-shadow: 0 0 5px #ccc; margin: 0 10px 10px; display: inline-block; cursor: move; }
    .thumb-file-name { font-size: 9px; }
</style>
<?php 
$addSelected = true;
?>
<p>
<?php  print Loader::helper('concrete/ui')->tabs(array(
    array('pane-thumbs', t('Items'), $addSelected),


and the get_thumbs.php located in /packages/vivid_thumb_gallery/blocks/vivid_thumb_gallery/tools/
<?php 
defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Core\File\Type\Type as FileType;
function thumbSort($array, $on, $order=SORT_ASC)
{
    $new_array = array();
    $sortable_array = array();
    if (count($array) > 0) {
        foreach ($array as $k => $v) {
            if (is_array($v)) {
                foreach ($v as $k2 => $v2) {
                    if ($k2 == $on) {
                        $sortable_array[$k] = $v2;
                    }
                }


Thank you again.
HardOne replied on at Permalink Reply
HardOne
Well, after submitting the composer form, the POST request aborts.

POST   (Aborted)   application/json (NS_BINDING_ABORTED)   http://mysite.local/index.php/ccm/system/panels/details/page/composer/publish?ccm_token=1431080677:1881d5dc1c921be2910f05610a218435&cID=225


I'm not sure if this is the cause or a result of my problem. And even worse, I have no idea how to debug this. I guess that after publishing a page from composer the reload of that page causes the POST request abort.

I really appreciate any feedback. Thanks.