Stuck on making template for Express List Block - Showing images
PermalinkSince the Slack/IRC bridge seems to be broken, I'm going to post here, hopefully I can get some help.
I'm trying to create a template for the Express List Block, initially to override when Images are present. Currently the block just says the name of the file and hyperlinks to the image. What I want instead is to actually show the image instead.
I think I've found the relevant section of the view.php file, however I don't think I'm using the methods correctly here as my testing results in php error pages complaining about a method that doesn't exist (at least, how I'm using it).
Here is what I have so far, starting at line 98 in the original view.php:
foreach ($result->getItems() as $item) { ?> <tr class="<?=$rowClass?>"> <?php foreach ($item->getColumns() as $column) { if ($column->getAttributeTypeHandle() == 'image_file') { ?> <td><img src="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>"></td> <?php } elseif ($controller->linkThisColumn($column)) { ?> <td><a href="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>"><?=$column->getColumnValue($item);?></a></td> <?php } else { ?> <td><?=$column->getColumnValue($item);?></td> <?php } ?> } <?php
I will want to revisit how the if/else's work, as they're not quite how I want right now. But I'm trying to figure out how to roughly get the image to show.
The error being thrown is "Call to undefined method Concrete\Core\Search\Result\ItemColumn::getAttributeType()"
Which makes sense as I dig into the API documentation, however I am not entirely sure how to achieve what I want at this point, as I don't know what I can do with "$key", which seems to be a value I can retrieve from the "ItemColumn" aspect (unsure which proper term to use here). I know other "aspects" seem to have the ability to tell if it's an image, but I'm not sure how to bridge that gap right now.
I also added this to the beginning, but it didn't help, unsure if actually needed at all (line 6):
I've been piecing this together from other sources of info like forum posts, etc, no clear answer just yet. Any help would be appreciated! Thanks!

if ($column->getAttributeType() == 'image_file') { ?>
So yeah, it is being used (just not accurately represented in the original post), and I'm not sure what I should change about how I'm accomplishing this. Namely, I want to tell if the "column" entry is an image file type or not, then act based on that.
So remove the ak_ and you'll get the attribute's handle.
From there grab the attribute and from it grab the type's handle
edit: to clarify, I'm not yet sure how to _derive_ the methods to meet the functions you just described. The API documentation really is not self-indicative.
https://www.concrete5.org/marketplace/addons/omni-gallery/...
As an extreme example, it can pretend to list the express objects as pages using a page list template, where the page list template thinks it is listing pages, but is actually listing the express object and its attributes.
Furthermore, I need to better understand how to do templates as there's a lot of other blocks I need to write them for and I need a better understanding to do that.
(it can handle pagination)
$columnKey = $column->getColumnKey(); // ak_some_attribute_handle $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express) $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category // some columns are not for attributes but for other objects like associations or default fields so make sure you do have an attribute before getting its type if ($attribute && is_object($attribute)) { $attrTypeHandle = $attribute->getAttributeTypeHandle(); // do your stuff with $attrTypeHandle }
The line where you're getting the category should probably be outside the loop that runs through all the columns since it never changes. I let you do that properly.
I hope this helps
<tr class="<?=$rowClass?>"> <?php foreach ($item->getColumns() as $column) { $columnKey = $column->getColumnKey(); // ak_some_attribute_handle $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express) $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category // some columns are not for attributes but for other objects like associations or default fields so make sure you do have an attribute before getting its type if ($attribute && is_object($attribute)) { $attrTypeHandle = $attribute->getAttributeTypeHandle(); // do your stuff with $attrTypeHandle if ($attrTypeHandle == 'image_file') { ?> <td><img src="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>"></td> <?php } elseif ($controller->linkThisColumn($column)) { ?> <td><a href="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>"><?=$column->getColumnValue($item);?></a></td>
echo $attrHandle . ' ' . $attrTypeHandle . '<br>';
And see what happens
$columnKey = $column->getColumnKey(); // ak_some_attribute_handle $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle echo $attrHandle . ' ' . $attrTypeHandle . '<br>'; $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express) $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category
This was the output just above the block it seems:
xEntryDateCreated xEntryDateModified game_name game_thumbnail text ociation_111e5cde-26bd-11eb-8d56-2221c0b44dd4 image_file ociation_8da745cb-3fc4-11eb-8d56-2221c0b44dd4 image_file ociation_b950c478-26c3-11eb-8d56-2221c0b44dd4 image_file
The "Date Modified" column is where it tries to put an img tag, and then every other column visually appears "blank", suggesting to me the iteration breaks after it encounters something that triggers the img replacement once. Unsure if that's correct or not.
$attrTypeHandle = $attribute->getAttributeTypeHandle();
game_name text game_thumbnail image_file
And specifics of where I put it....
<?php foreach ($item->getColumns() as $column) { $columnKey = $column->getColumnKey(); // ak_some_attribute_handle $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express) $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category // some columns are not for attributes but for other objects like associations or default fields so make sure you do have an attribute before getting its type if ($attribute && is_object($attribute)) { $attrTypeHandle = $attribute->getAttributeTypeHandle(); // do your stuff with $attrTypeHandle // BELOW IS TESTING LINE echo $attrHandle . ' ' . $attrTypeHandle . '<br>'; //TESTING LINE FOR MNAKALAY // ABOVE IS TESTING LINE if ($attrTypeHandle == 'image_file') { ?> <td><img src="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>"></td> <?php
Only attributes have an attribute type. You said you needed to know which attribute had an image. That's the second one with the attribute type of image_file.
So what we can say is that at least that aspect of the code works correctly
Now you don't see anything because you are outputting an image <img> but instead of the URL to an image you are using the URL to a page
<img src="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>">
So correct the line above like this and see if it works
<img src="<?=$attribute->getPlainTextValue()?>">
Call to undefined method Concrete\Core\Entity\Attribute\Key\ExpressKey::getPlainTextValue()
<img src="<?=$attribute->getController()->getPlainTextValue()?>">
Call to a member function getValue() on null
for "...concrete/attributes/image_file/controller.php"
line 85
$f = $this->getAttributeValue()->getValue();
<?php $entry = $item->getEntry(); foreach ($item->getColumns() as $column) { $columnKey = $column->getColumnKey(); // ak_some_attribute_handle $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express) $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category // some columns are not for attributes but for other objects like associations or default fields so make sure you do have an attribute before getting its type if ($attribute && is_object($attribute)) { $attrTypeHandle = $attribute->getAttributeTypeHandle(); if ($attrTypeHandle == 'image_file') { $fv = $entry->getAttribute($attribute); if (is_object($fv)) { ?> <td><img src="<?=$fv->getURL())?>"></td>
Make sure you replace the whole foreach loop in your code from opening bracket to closing bracket.