Jump to content


Photo

module request: Page List "image" option


  • Please log in to reply
22 replies to this topic

#1 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 347 posts
  • 165

  • LocationKatoomba, AU

Posted 07 May 2012 - 07:58 PM

Hi all,

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 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

Posted 08 May 2012 - 02:41 AM

I think , since I'm the orginator of this, I'll give it a try to make something with a module.

@somartist | modules created | support me, flattr my work flattr.com


#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3385

  • LocationAtlanta, GA

Posted 08 May 2012 - 11:43 AM

Count me in to help if needed. I think this may be one that belongs in the core, though have avoided it thus far since it gets the core involved in specific fieldtype output. But this may be an okay compromise to make if done directly in ProcessPageList. Other than that, I think that a module is definitely a good way to do it too.

#4 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

Posted 08 May 2012 - 04:49 PM

Here it is a first test version.

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 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 347 posts
  • 165

  • LocationKatoomba, AU

Posted 08 May 2012 - 06:27 PM

Philipp for a 'first test version' this is awesome!

Regards
Marty

#6 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 347 posts
  • 165

  • LocationKatoomba, AU

Posted 08 May 2012 - 06:59 PM

Hi Philipp,

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?

Posted Image

This is such a great module.

Regards
Marty

#7 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

Posted 09 May 2012 - 01:45 AM

Hey smd, glad it works well for you.

I just pushed an update. Fixed border and removed comma after thumbnail.

@somartist | modules created | support me, flattr my work flattr.com


#8 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3385

  • LocationAtlanta, GA

Posted 09 May 2012 - 12:14 PM

Great module Soma! I really like having this functionality, and you've done a nice job putting it together. It's easy to see how useful this is seeing it in action--I will be using this for sure.

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 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

Posted 09 May 2012 - 12:44 PM

Thanks Ryan!

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


#10 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3385

  • LocationAtlanta, GA

Posted 09 May 2012 - 12:54 PM

Add this to the top of your getModuleConfigInputfields() function. This should also solve the undefined variable notices:

$data = array_merge(self::$defaults, $data);


#11 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

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 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

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 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

Posted 10 May 2012 - 09:51 AM

Sorry for the triple post.

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 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3385

  • LocationAtlanta, GA

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 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 347 posts
  • 165

  • LocationKatoomba, AU

Posted 10 May 2012 - 08:24 PM

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

#16 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

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 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

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 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 347 posts
  • 165

  • LocationKatoomba, AU

Posted 11 May 2012 - 03:58 AM

That's cool. Not a big deal at all.
Thanks!

#19 Soma

Soma

    Hero Member

  • Moderators
  • 3,408 posts
  • 1942

  • LocationSH, Switzerland

Posted 11 May 2012 - 05:12 AM

Good news for your Marty. I got the resizing working for crop images! :) I did some magic resizing using PW ImageSizer class. It now generates a extra thumbnail of the thumbnail using the size you specify in the module settings. They get named "widthxheight_thumbnail_imagename.jpg".

I just commited an update. Let me now if any issue arises.

@somartist | modules created | support me, flattr my work flattr.com


#20 diogo

diogo

    Hero Member

  • Moderators
  • 2,068 posts
  • 1179

  • LocationPorto, Portugal

Posted 11 May 2012 - 05:32 AM

This is great Soma!! works wonderfully here :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users