Displaying a thumbnail image in CollectionTree list

Well, I’ve been working on this for days but my php noobness is a blocker, I think. I’ve managed to customize the visual appearance of the CollectionTree nested list that appears here, so it’s a nice, responsive grid: http://michaelsand.com/archives/collection-tree (sorry, sign in with username guest and password guest2018).

I’d like to display a representative thumbnail for the child collections in this list, but I’m stumped. Pretty confident I should be making changes to /archives/plugins/CollectionTree/views/helpers/CollectionTreeFullList.php but that’s as far as I can get. Every attempt at adding content to the list output breaks the page all together (including my attempts at simple echo statements).

So, not only do I need to figure out what code snippet would actually display a child thumbnail, I also need to figure out where in the existing code to add it. (I’d like it to appear within its appropriate <li>, above the collection title.)

I’m happy to hack away at it on my own, if someone can at least point me in the right direction. Thanks in advance!

(Oops; let me know if this should be moved to the Plugins category!)

It looks like that does get tricky very quickly. So, I can’t really say that I see the exact path to what you are looking for. Instead, here’s what I would suggest looking in to, and we’ll go from there.

First, you might need to look at both CollectionTreeFullList.php and CollectionTreeList.php. Looks like the former is for everything from the top level of Collections down, but that also gets passed along to the latter. So, both are probably in play for what you are working on.

For testing where the most simple changes happen, I’d first try just adding something stupid where those functions build up the html for display. Both start the interesting part with $html = '<li> On the next line, I’d put in $html .= '<p>It works!</p>, just to see where changes actually occur (changing up the messages for the different files and locations will also help).

After that looks happy, the meat of the problem is digging up “representative” images. The simplest idea of representative is the first image from the first item in the collection being displayed. I’d start, then, with digging that up.

Maybe start by adding in a query on the Items table to get a single Item that belongs to the Collection.

I think something like get_record('Item', array('collection_id' => $collectionId)); is along the right lines.

Then, dig up a file for the Item and display it.

That’s very general, and is surely missing details. But that’s the best route that I can see right away to start trying things.


Update – forgot to say that $collectionId above is really the same $collection['id'] you’ll see in both of the CollectionTree helpers as it builds up the HTML inside the link_to_collection() business.

Well, you’re correct that the file to mess with is likely CollectionTreeList.php (when I replace it with simple html, it displays properly). Interestingly, if on that page I replace only the following line with plain html…:

$html .= $this->collectionTreeList($collection['children'], $linkToCollectionShow);

…the main Browse Projects page (http://michaelsand.com/archives/collection-tree) still displays the text links for both parent and child collections, in addition to the plain html insert (“It works”). However, on individual Collection show pages (e.g. http://michaelsand.com/archives/collections/show/12), it completely replaces the text link to the child collections that display at the bottom of that page. Not a deal-breaker, but they’re connected.

So, if I can figure how to call any image within each child collection, I should be able to get there. The get_record('Item', array('collection_id' => $collectionId)); bit doesn’t seem to do it, regardless of where I place it.

That original line — $html .= $this->collectionTreeList($collection['children'], $linkToCollectionShow); — appears to be the nested link I want to add the image to (as I said, if I comment it out, everything still displays correctly on the main Browse Projects page, though disappears from the bottom of the individual collections show page).

No amount of manipulation of that line, though (adding the suggested get_record query, replacing it, etc) seems to work, though. It either breaks the page all together, or simply doesn’t change the display (other than removing the links on the collections show page, which I care less about).

Separately, the following code in /archives/applications/views/scripts/collections/show.php correctly displays a representative thumbnail (most recently added, I believe) for child collections show pages (e.g. http://michaelsand.com/archives/collections/show/15):

    <?php if ($collectionImage = record_image($collection, 'square_thumbnail')): ?>
        <?php echo link_to($this->collection, 'show', $collectionImage, array('class' => 'image')); ?>
    <?php endif; ?>
    <?php if ($description): ?>

So I’ve been playing with trying to insert/tweak that code into CollectionTreeList.php, to no avail.

Thanks so much for the help! I know this is doable… :smiley:

Looks doable, and :rainbow:s and :unicorn:s are imminent!

I hadn’t thought about record_image approach, but that makes sense. Indeed, I might have been making it more complicated than needed. If within the helper you can dig up the Collection object from the database, and pass that in to the separate code you listed for getting a $collectionImage, that might be the small variation you need.

Oops, never saw your response; sorry!

So is the idea that the Collection object would replace the $collection variable in the record_image function below?

<?php if ($collectionImage = record_image($collection, 'square_thumbnail')): ?>
        <?php echo link_to($this->collection, 'show', $collectionImage, array('class' => 'image')); ?>
<?php endif; ?>

And then that whole bit could be dropped into the CollectionTreeFullList helper file? I think part of my problem is that I’m not entirely clear on the relationship between the Collection object and the record image. :thinking:


This topic was automatically closed after 250 days. New replies are no longer allowed.