thmsnhl Posted July 30, 2015 Share Posted July 30, 2015 Hi, I'm currently working on a small blog for a friend of mine, he wants to use external images as title Images in his posts and therefore I need some kind of backend gallery, to collect all URLs. To make this a little bit more manageable I want to include a thumbnail in the backend next to the URL field. Now I'm asking myself some things: Is there a solution already? I searched the forums and fieldtypes for something like this but did not find one. How can I create my own fieldtype to solve this problem? Maybe there is a "mix and match"-solution with URL- and Image-Fieldtype?! I'm thankful for every answer! Cheers, Tommy Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 30, 2015 Share Posted July 30, 2015 You could just hook the render function of InputfieldUrl and add an image tag before the input for that exact field. This would be the laziest of methods. Link to comment Share on other sites More sharing options...
thmsnhl Posted July 30, 2015 Author Share Posted July 30, 2015 Thank you for the quick response.Could you explain a little more in detail where I have to define this hook and what has to be in there to render an image?I checked the module files for about an hour and still I'm not sure where to put my own code. Link to comment Share on other sites More sharing options...
Peter Knight Posted July 30, 2015 Share Posted July 30, 2015 Do you mean that in the Admin you want a thumbnail beside the title? Link to comment Share on other sites More sharing options...
thmsnhl Posted July 30, 2015 Author Share Posted July 30, 2015 Yes, exactly Peter. Link to comment Share on other sites More sharing options...
horst Posted July 30, 2015 Share Posted July 30, 2015 (edited) I'm not completely sure if this is possible within the admin, but I think yes: one way can be to build a simple little module, another way can be to use one of the new implemented _ready.php | _install.php etc. files, if you use the one of the latest dev versions (PW 2.6.9+ ??) But regardless of that, you need to hook into after InputfieldURL::render Within your function you fetch the result ($event->return) and the url, if any given and prepend an image tag to the result. pseudo code, simplified: $url = ... ; // you need to fetch the url here $event->return = "<img src='{$url}' width='100' alt='' />" . $event->return; $event->replace = true; . EDIT: After rethinking it, I think you need to build a little custom module and cannot use the new _ready.php etc. files, but would be nice if some one can clarify this more precisly than I currently can. Edited July 30, 2015 by horst Link to comment Share on other sites More sharing options...
Sergio Posted July 30, 2015 Share Posted July 30, 2015 Take a look at this module by Adrian -> http://modules.processwire.com/modules/process-get-video-thumbs/ I think you can adapt it to your use case. Also, maybe it is worth to study the Embed.ly API http://embed.ly/ Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 30, 2015 Share Posted July 30, 2015 wire()->addHookAfter('InputfieldURL::render', function($event) { $field = $event->object; if($field->name != "yourField") return; $url = $field->value; if($url) return $event->return = "<img src='$url' width='100' alt='' />" . $event->return; }); This should do the job pasted at the beginning of site/templates/admin.php. 4 Link to comment Share on other sites More sharing options...
Peter Knight Posted July 30, 2015 Share Posted July 30, 2015 Yes, exactly Peter. Soma has a Module called Page List Image Label. Would that work? You could also try the ListerPro module (paid but very reasonably priced) where you can create a custom view of lists of pages arranged by columns. One of those columns could be an image associated with a page. Next column could be the title. Link to comment Share on other sites More sharing options...
thmsnhl Posted July 31, 2015 Author Share Posted July 31, 2015 Thank you LostKobraKai, this worked straightaway. This community is awesome! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now