Block with thumbnail/title/linked URL?

Permalink
Hi everyone,

I'm trying to create a block that contains a thumbnail field, a title field, and a URL field that will wrap around a small icon with a rollover.

Here's a screenshot of what I'm trying to do:

http://imgur.com/oI67s.jpg

I'm new to PHP and am fumbling hopelessly, trying to get this to work. Any help would be awesome. Here's what I have for the block:

add.php:

<?php  
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'fID', t('Choose File'), $bf)
?>
<?php echo $form->label('content', 'Name');?>
<?php echo $form->text('content', array('style' => 'width: 320px'));?>
<?php $bf = File::getByID($fID);?>


controller.php:

<?php
    class BasicTestBlockController extends BlockController {
        var $pobj;
        protected $btDescription = "A simple testing block for developers.";
        protected $btName = "Basic Test";
        protected $btTable = 'btBasicTest';
        protected $btInterfaceWidth = "350";
        protected $btInterfaceHeight = "300";
    }
?>


db.xml:

<?xml version="1.0"?>
<schema version="0.3">
    <table name="btBasicTest">
        <field name="bID" type="I">
            <key />
            <unsigned />
        </field>
        <field name="fID" type="I">
            <unsigned />
         <default value="0" />
        </field>
        <field name="content" type="X2">
        </field>
    </table>
</schema>


edit.php:

<?php  
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'fID', t('Choose File'), $bf)
?>
<?php echo $form->label('content', 'Name');?>
<?php echo $form->text('content', $content, array('style' => 'width: 320px'));?>
<?php $file = File::getByID($fID);
$filePath = $file->getVersion()->getRelativePath();?>


view.php:

<?php  
$file = File::getByID($fID);
$filePath = $file->getVersion()->getRelativePath();
 ?>
<div style="height: auto; width: auto; float: left;"><?php echo $content?></div>
<div style="height: auto; width: auto; float: left;">
<?php  
echo '<img src="' . $filePath . '" />';
 ?>
</div>


I'm sure it's something relatively simple, but to the PHP beginner it's a little overwhelming. Thanks for help!

stephmars
 
stephmars replied on at Permalink Reply
stephmars
Anyone? :(
JimboJetset replied on at Permalink Reply
JimboJetset
You haven't actually stated what the problem is..?
stephmars replied on at Permalink Reply
stephmars
Oh sorry! I'm trying to create a field for a URL that wraps around an image, so that the image is linked.

I've tried many variations that I've tried to extract from concrete's standard blocks, with no luck.
hursey013 replied on at Permalink Reply
hursey013
You can accomplish the same thing you are trying to do with your block by using a custom template with the page list block. By default, the page list block will show the title of a page, the description, and the link to the actual page. Following this tutorial shows how to easily add a thumbnail as well:http://www.codeblog.ch/2009/03/concrete5-templates...

If you really want to make it your own block, Remo also has a good sample block you can base yours off of here:http://www.codeblog.ch/2009/06/concrete5-staff-table/...
stephmars replied on at Permalink Reply
stephmars
Thank you, I will look into this right away!
stephmars replied on at Permalink Reply
stephmars
Okay, I followed Remo's tutorial, and got this error: "Fatal error: Call to a member function getFileRelativePath() on a non-object in [path]/blocks/page_list/templates/thumbnail.php on line 18"

I'm not sure that going the route of a custom template would be the best or most efficient choice since I already have all the content (with the exception of the thumbnail and link) built into a block. I'm not familiar enough (yet) with PHP syntax to successfully extract only the information that I need from the preexisting page_list template...

The block I have (each component shown in my original post, above) works great right now as it is, I just need a bit of help or helpful steering that will show me what I need to do, or add, to what I already have, to make the extra 2 fields I need.

Is it as simple (relatively) as taking this part of the code in view.php:

<?php  
echo '<img src="' . $filePath . '" />';
 ?>


And wrapping it in something like...

<?php  
echo '<a href="' . $linkPath . '"> <img src="' . $filePath . '" /> </a>';
 ?>


?

(That of course doesn't work, but am I headed in a vaguely good direction? And if so, what do I need to add to the db.xml?)
DavidMIRV replied on at Permalink Reply
DavidMIRV
$filePath = $file->getRelativePath($fID);
///Alternative
$filePath = File::getRelativePathFromID($fID);


using either should give you the path to the most recent version
DavidMIRV replied on at Permalink Reply
DavidMIRV
opps forgot the File::getByID() call on the first one.. but you got the idea
DavidMIRV replied on at Permalink Reply
DavidMIRV
wait maybe I'm misunderstanding.. Do you need the Concrete5 Page Selection Popup for your link?
stephmars replied on at Permalink Reply
stephmars
No, not the Page Selection.

What I want to do is have 1 field for a thumbnail, and 1 field for a URL that will wrap around the thumbnail so the _effect_ is:

<a href="#"><img src="image.jpg"></a>

I have an existing block with a couple other fields. All I want to do is add these 2 additional fields. Is this doable?
stephmars replied on at Permalink Reply
stephmars
Thanks, but this didn't work. :(
DavidMIRV replied on at Permalink Reply
DavidMIRV
Is the fID set? have you echo'd it out to verify it's saving ?

this should be relatively simple
<?php
$fp = File::getRelativePathFromID($fID);?>
?>
<a href="<?php echo $content?>"><img src="<?php echo $fp;?>" /></a>


If you're not getting an image displayed there check that the fID is saving and being fetched..

then the problem would be the edit/add(.php)
stephmars replied on at Permalink Reply
stephmars
Thank you for this, I'm going to try it out now, I just need to know which file(s) to add it to. Are you saying I need to add that code to both the edit.php and add.php?
DavidMIRV replied on at Permalink Reply
DavidMIRV
what I provided would be what I think you want in your view? a Image wrapped in a URL ? If not then I am confused..

Also the image block can do this out of the box..
stephmars replied on at Permalink Reply
stephmars
I think I may have found the answer in the preexisting "Image" block (fingers crossed).

Thank you so much for your help so far, though. I know it's a lot to ask, for programmers to take time out of their day to help us little guys (and girls)! So, much appreciated. :)
larryp7639 replied on at Permalink Reply
Great post! It's very nice. Thank you so much for your post.

_______________
http://moviesonlinefree.biz