How to save asset library image object as a page attribute?

Permalink
Hi all,

So I've been trying to replace a normal form image element with an image loader from the asset library to access some callback functions.

so I want to replace this ->

echo $akt->render('form', $tvalue, true);

with this ->
$al = Loader::helper('concrete/asset_library');
$al->image('ccm-b-image-'.$bID, 'thumbnail', t('Choose Image'), $bf);

The reason is, that I want to use the crop feature from the composer :

<script type="text/javascript">
ccm_triggerSelectFileComplete = function(fID, af) { 
   // af = ccm-b-image-blockid
   var td = $("#ccm-image-composer-thumbnail-" + af.substring(12));
   ccm_alGetFileData(fID, function(data) {
      crop = false;
      td.html('');
      dw = data[0].width;
      dh = data[0].height;
      var tw = $("#ccm-image-composer-thumbnail-" + af.substring(12)).attr("target-width");
      var th = $("#ccm-image-composer-thumbnail-" + af.substring(12)).attr("target-height");
      if (tw != dw) {
         dw = '<span style="color: #f00">' + dw + '</span>';
         crop = true;
      }


Unfortunately I am very unskilled in this field, so I need some help..

As mentioned I want to save my new $al into an attribute called "thumbnail", but here I am lost. How do I pass the file object to my controller with the rest of the form ?

I have pasted my view and my controller to get a hold of what's going on.. (the view has both the original form element and the al element right now when I am looking for a solution)

Controller :
http://pastebin.me/8d6b367a7ee76be70f944d9b96133a17...
View:
http://pastebin.me/8d6b367a7ee76be70f944d9b9613357b...

I really hope someone can tell me how to manage this, as I am very new to this :-)

pixel8
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
This line of code you have:
$al->image('ccm-b-image-'.$bID, 'thumbnail', t('Choose Image'), $bf);

...is passing in the variable $bf, which is supposed to be an image object. But you haven't set that variable to actually be an image object. To get an image object, you call File::getByID(123) [where 123 is the file id].
It looks like you want the 'thumbnail' field to be the file id of the chosen image perhaps? If that's the case, then insert this new line of code above that other one:
$bf = empty($thumbnail) ? null : File::getByID($thumbnail);


In terms of learning how it works, I often find it helpful to see one piece of functionality isolated from everything else (so I can see what code is essential to that functionality working versus what's optional or what's related to something else entirely). If you want to do that, I'd suggest using Designer Content (http://www.concrete5.org/marketplace/addons/designer-content/... ) to generate a block with just one image field in it (and with no extra options on that field)... then look at the code it generates.

Good luck!

-Jordan