Multiple assets selected in add.php and edit.php

Permalink
I have a project that requires a custom block. I'm pretty new to the custom block creation part of concrete5. The project needs the block to be able to choose an image and a PDF file. These are 2 separate fields. An excerpt of the code is as follows:

<?php
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
'type' => 'image'
);
$al = Loader::helper('concrete/asset_library');
$bf=0;
$of=0;

if($controller->getFileID("image")>0){
$bf=$controller->getFileObject("image");
}

if($controller->getFileID("document")>0){
$of=$controller->getFileObject("document");
}
?>


<div class="ccm-block-field-group">
<h2><?php echo t('Image')?></h2>
<?php echo $al->image('ccm-b-image', 'imageID', t('Choose Image'), $bf);?>
</div>

<div class="ccm-block-field-group">
<h2><?php echo t(' Members CV')?></h2>
<?php
echo $al->file('ccm-b-document', 'cvID', t('Choose CV'), $of);
?>
</div>

In both the edit and add php files if you dare to select a PDF or image file in the second field concrete5 produces an error popup that makes absolutely no sense. In fact the popup contains the homepage stripped of any HTML tags! I've even compared what I've done to the image block and there appears to be no real difference except I'm using $al->file instead of $al->image for the second field.

I'm getting really frustrated and the project deadline is rapidly approaching. Does anyone know what I'm doing wrong?

Thanks in advance for any help.

kmcwhan
 
jordanlev replied on at Permalink Reply
jordanlev
Use Designer Content:
http://www.concrete5.org/marketplace/addons/designer-content...

I'm not sure what the exact problem with your code was, but when you see an "error" that's just a normal page on your site, it's usually showing you the "404 page not found" error -- which again, I don't know why that would happen in your case.
I have experienced problems before when trying to combine more than one selection control in the same edit form, but usually that's related to the WYSIWYG editor and not the file selectors.

Anywho... just use Designer Content, it will build this block for you automatically. Then look at the code it generated to see how to do it yourself in the future (if you're interested in learning).
kmcwhan replied on at Permalink Reply
kmcwhan
Thank you for your reply. I will give it a go and see what happens. I'm always interested in learning so it will be interesting to see how it is done. Thanks again for your help.
kmcwhan replied on at Permalink Reply
kmcwhan
I've installed and downloaded the Designer Content stuff. It works a treat. Thank you.

When I look at the code it's virtually identical. Now that's annoying!

Thanks again.
jordanlev replied on at Permalink Reply
jordanlev
Hmm... well you might try removing this from the top of your code:
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
'type' => 'image'
);

(I'm not actually sure that does anything -- but if it does then it's restricting the file picker to just images which won't work for your pdf's).

Actually, it might instead be due to your use of the name "cvID" for the field -- I wouldn't expect this to be a problem, but "cvID" is used a lot in the core code (short for CollectionVersionID), so it may be getting its wires crossed when it sees that.

Meh... these computers are so annoying sometimes -- often just one character wrong can screw the whole thing up.
kmcwhan replied on at Permalink Reply
kmcwhan
Ah. Thanks for that. I didn't think that the cvID would conflict with anything but what you have written makes sense, that may very well have been my issue. Thanks for all the help and pointers.