module request: Page List "image" option
#1
Posted 07 May 2012 - 07:58 PM
Following on from this thread: http://processwire.c...st-image-label/
I'd like to sponsor a module that gives me (and any PW user too) the option to display image thumbnails in the page list. I know you can specify which fields to display in the page list in Templates > Advanced.
Because I do a bit of work for artists this would be great option for me (and probably others) to have. I'd like it to work with Antti's Thumbnails module too.
Please get in touch if you're interested: martin@smd.net.au
Regards
Marty
#2
Posted 08 May 2012 - 02:41 AM
@somartist | modules created | support me, flattr my work flattr.com
#3
Posted 08 May 2012 - 11:43 AM
#4
Posted 08 May 2012 - 04:49 PM
Got it working with regular image fields, or thumbnail cropimages fields.
You can specify any image field using the image field name in the advanced template setting for page label. To output an thumbnail (from the Thumbnail module) just use the dot notation. fieldname.thumbnailname (as specified in the thumbnail field settings)
There's some option on this module for controlling the size of image and the container size, padding, colors.
https://github.com/s...eListImageLabel
Edit: Added support for multiple image fields. It will always take the first image.
@somartist | modules created | support me, flattr my work flattr.com
#5
Posted 08 May 2012 - 06:27 PM
Regards
Marty
#6
Posted 08 May 2012 - 06:59 PM
I've only noticed two tiny things that I can't work out. I set a border colour which I can't get to show up around the thumbnail. And is there any way I can remove the comma that appears after the thumbnail?

This is such a great module.
Regards
Marty
#7
Posted 09 May 2012 - 01:45 AM
I just pushed an update. Fixed border and removed comma after thumbnail.
@somartist | modules created | support me, flattr my work flattr.com
#8
Posted 09 May 2012 - 12:14 PM
A few comments:
1. On the module edit screen, I get a bunch of notices about undefined variables. Probably because I'm in debug mode, but wanted to mention it still.
2. I see the defaults in the .module file, but they weren't populated in my config screen, so I was confused about whether the fields needed to be populated or not. If they don't, maybe adding a $field->collapsed = Inputfield::collapsedBlank; to the optional fields would clarify they are optional. You might also add a $field->notes = "If left blank, a default will be provided"; or something like that.
3. When displaying a page that has no image, it shows a broken image. I think it'd be better if it showed a placeholder (WillyC's face?) or just the box with no image in it.
#9
Posted 09 May 2012 - 12:44 PM
About the defaults. How can I get the defaults in the getModuleConfigInputfields function? I wasn't able to access them from there. How is the simplest way to handle it?
@somartist | modules created | support me, flattr my work flattr.com
#11
Posted 09 May 2012 - 01:18 PM
Add this to the top of your getModuleConfigInputfields() function. This should also solve the undefined variable notices:
$data = array_merge(self::$defaults, $data);
Ahh cool. That works only if the var $defaults is static. Well I don't understand enough why, but It works! Thanks Ryan.
Is it correct that I can't merge the defaults to a local ($this->key) in the init() and have it available in the hook "addImageLabel" function? Is that because it is a hook. I had to put the merging (foreach loop) in the function to get it work.
@somartist | modules created | support me, flattr my work flattr.com
#12
Posted 09 May 2012 - 01:34 PM
3. When displaying a page that has no image, it shows a broken image. I think it'd be better if it showed a placeholder (WillyC's face?) or just the box with no image in it.
Hmm, I can't see any broken image when there's none on the field. It doesn't output anything if there's no image when I test. Although looking at my own code I can't see why, cause it should. So it seems the only reason is because ($v instanceof Pageimage) does fail if there's no image.
Edit: Even bigger HMM, ok now I see it. It only happens with "multiple" images fields.
Edit2: Ok I fixed all, and have added new option to specify an No-Image Text and text color. Also the module options are populated with the defaults at first run. May need deinstall and reinstall to have a default install.
Just commited an update:
https://github.com/s...eListImageLabel
@somartist | modules created | support me, flattr my work flattr.com
#13
Posted 10 May 2012 - 09:51 AM
Again. I'm testing with if there's not image populated. It doesn't work same with single image fields.
I'm doing a check
if(($v instanceof Pageimage) || ($v instanceof Pageimages)){
...
If it's a multi mage field (Pageimages) it returns true and the magic happens even if the field is empty.
If it's a single image field (Pageimage) it doesn't return true if the field is empty.
So it doesn't return the "no-image" text as I wanted.
Have you any idea why?
@somartist | modules created | support me, flattr my work flattr.com
#14
Posted 10 May 2012 - 04:23 PM
Is it correct that I can't merge the defaults to a local ($this->key) in the init() and have it available in the hook "addImageLabel" function? Is that because it is a hook. I had to put the merging (foreach loop) in the function to get it work.
PW populates your config variables to the module in the time between __construct() and init(). So when init() is called, your config variables have already been populated to the module. As a result, the __construct() is a good place to populate defaults. In your case, you could do this in your __construct():
foreach(self::$defaults as $key => $value) $this->set($key, $value);
If it's a multi mage field (Pageimages) it returns true and the magic happens even if the field is empty.
If it's a single image field (Pageimage) it doesn't return true if the field is empty.
I don't think that a Pageimage (singular) is applicable here since all image fields are multi-image fields behind the scenes. The existence of a single image field is just a type of output formatting used on the front end of your site. I believe output formatting is turned off in the case of your module, so you should be able to assume that all image fields are multi image fields (Pageimages). As a result, I would perform the check like this:
if($v instanceof Pageimages && count($v)) {
// ...
}
#15
Posted 10 May 2012 - 08:24 PM
Just wondering: is there's a way (apart from setting a image width in the module's css) to affect the scale of the FieldtypeCropImage thumbnail?
Regards
Marty
#16
Posted 11 May 2012 - 03:50 AM
I don't think that a Pageimage (singular) is applicable here since all image fields are multi-image fields behind the scenes. The existence of a single image field is just a type of output formatting used on the front end of your site. I believe output formatting is turned off in the case of your module, so you should be able to assume that all image fields are multi image fields (Pageimages). As a result, I would perform the check like this:
if($v instanceof Pageimages && count($v)) { // ... }
Outputformatting is turned on! I had to turn it off to get it to work with testing only for "Pageimages". With the OF turned on, it is not possible with single image field. If the image field isn't populated, it will never be true wether with Pageimages nor with Pageimage.
So it's all a bit wierd. So I have OF turned off.
But strange thing is, then I have to test again inside the if($v instanceof Pageimages){..} routine for if(count($v) && $v instanceof Pageimages){..} to test for if it's a multi or a single, to then call it with first() or without if it's single. Like this:
if(count($v) && $v instanceof Pageimages){
$thumb_url = $page->$field->first()->size($size[0],$size[1])->url;
} else if(count($v)) $thumb_url = $page->$field->size($size[0],$size[1])->url;Don't really understand why.
@somartist | modules created | support me, flattr my work flattr.com
#17
Posted 11 May 2012 - 03:54 AM
Hi Philipp,
Just wondering: is there's a way (apart from setting a image width in the module's css) to affect the scale of the FieldtypeCropImage thumbnail?
Regards
Marty
I knew you would ask this question. No it's not possible cause the crop images aren't regular PW images. At least not without changing the Thumbnail module or write my own functions to resize the croped image. Have to further investigate and ask apeisa or ryan if there would be an easy way. For now it would only be possible over the css.
@somartist | modules created | support me, flattr my work flattr.com
#18
Posted 11 May 2012 - 03:58 AM
Thanks!
#19
Posted 11 May 2012 - 05:12 AM
I just commited an update. Let me now if any issue arises.
@somartist | modules created | support me, flattr my work flattr.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













