(I hope I'm posting this to the right forum....)
I'm just getting started with Gallery2, and I'd really like to make it easier for my authors and editors to add/edit custom data. The best way to do that, it seems to me, would be to add the custom fields to the Edit Captions page.
I'm an experienced PHP developer, so I can probably figure out how to do this, but if it's a problem that's been solved already, or if there are places to read up on how that page is put together, or any hints at all that someone can give me, I'd love not to have to start from scratch. I haven't really been able to find anything useful in the poking around on here that I've done so far....
TIA.
Gallery version = 2.1.2 core 1.1.0.2
PHP version = 4.4.4 cgi
Webserver = Apache/1.3.37 (Unix) mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
Database = mysql 4.1.21-standard-log, lock.system=flock
Toolkits = ArchiveUpload, Exif, Getid3, ImageMagick, NetPBM, SquareThumb, Thumbnail, Gd
Acceleration = none, none
Operating system = Linux asclepius.site5.com 2.6.18-1-s5 #1 SMP Tue Oct 10 21:34:59 EDT 2006 i686
Default theme = matrix
Locale = en_US
Browser = Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7
Posts: 32509
no, as far as i know, this hasn't been done yet.
you'll need to edit modules/core/ItemEditCaptions.inc and modules/core/templates/ItemEditCaptions.tpl.
if it's a modification for your site only, it should be fairly straight forward. you'll have to copy some code from modules/customfields/ into the ItemEditCaptions controller, view and template.
if you want a solution that can be used in other galleries as well, you'd need to make it extensible and use the factory such that modules like customfield or multilang could register an implementation that would display some fields for each item in the caption view.
Posts: 8
Thanks for the quick response. I'll probably start by implementing it for just this site. Maybe down the line I'll turn it into an extension....
Posts: 8
Hmm.... is there a primer somewhere on how these pages are put together? I've never really delved into smarty, but I'm sure I can easily find a reference for that. I'm more thinking about the basic architecture of the code....
Thanks again....
Posts: 32509
i'm moving this topic to the development forums.
@smarty:
well, there's the smarty website and gallery .tpl examples to learn from. but we don't really have docs for that.
http://codex.gallery2.org/index.php/Gallery2:Tpl_Reference and http://codex.gallery2.org/index.php/Gallery2:Themes don't really help in this case.
Posts: 8
Ok, thanks. I guess I'll just struggle through. I'll post back a solution when I've got one....
Posts: 8
Ok, I've got it working, though I've been a bit kludgy with it, and am almost certainly not doing things in the most Galleryesqe fashion. I've modified two files:
modules/core/ItemEditCaptions.inc
For saving the data, around line 90, below:
add:
----
For viewing the data,
Around 227, below "/* build peers table */", add:
and add this:
$child->customFields = $customFields[$child->getId()];
inside the foreach loop just below the above.
===========
modules/core/templates/ItemEditCaptions.tpl
around line 90, below the "Description" textarea, add:
I think that's all I did. I know this doesn't handle the dropdown or album cases, but otherwise it seems to be working. Suggestions welcome, and if someone wants to tell me how to make this more upgrade-friendly, I'd love to hear about it.
Thanks again....
Posts: 16
Okay, I've made ItemEditCaptions to use a factory and customfield to register in it. Seems to work.
Only new fields can be added this way, title/summary/description/keywords are still hardcoded.
A question - should I continue and finish it up ? That would mean adding everything one can see on a page via a factory. And I'd add a "configure" link that would allow to chose what fields to see - if one wants to edit custom fields he can hide title/etc and multilang, for example. And as a thumbnail itself would be added via a factory, it could be replaced with a module to do bulk rotation.
A patch is attached.
Posts: 96
I am just about to embark on a similar customisation of the Edit Captions page (I prefer to think of it as Batch Edit). I am experimenting with Gallery2.2 and see that that already has the keywords field included here.
I just wanted to check if anyone has done anything more than is detailed in this thread? And has anyone tried to implement it for a drop-down?
I guess the answer to sergii's last post is 'yes', but I confess I know nothing as yet about factories. More homework ;-)
Posts: 16
Correct. The answer is yes. All features of CustomFields are fully supported (including multi-value selection lists from my other patch).
Posts: 96
sergii, I tried a patch -l of ItemEditCaptions.inc using the editcaptions-factory.diff_.txt file and get the error
Assertion failed: hunk, file patch.c, line 321
I am using the win32 patch.exe in UnxUtils
This is all a bit new to me. Can you either suggest another way to run the patch, or perhaps supply an updated ItemEditCaptions.inc based on the current release with your patch applied?
On second thoughts, I wonder if that's where the problem lies - I am using Gallery2.2, and maybe your patch only works with the released versions?
Thanks again, James
Posts: 16
failed assertion means a bug in your patch.exe, try another binary, e.g. from mingw.
the patch is for 2.1.2, right, but fixing it for 2.2. should be trivial (mainly correcting return array($ret->wrap(__FILE__, __LINE__), null); lines). Note that this patch should be applied after a patch from http://gallery.menalto.com/node/56409.
Posts: 96
May be trivial for someone of your obvious talent, but I'm swimming further and further out of my depth here. But it's always fun trying to learn new strokes ;-)
Posts: 69
Hi Sprugman, I've inserted the changes you mentioned above but now I get the error message
"Fatal error: Class 'CustomFieldHelper' not found in <......>\modules\core\ItemEditCaptions.inc on line 222"
when trying to acces the EditCaption page in the item menu.
Any suggestion what causes that? And no, I didn't use the patch as I can't do it at the computer I'm working on currently.
Thanks for help
Posts: 8
I'm afraid I barely know enough about how gallery works to implement what I wrote above, so I can't really help you.... (Sorry.) I guess I would start by doing a global search for the phrase "CustomFieldHelper", and see where that took me....
-Sprug.
Posts: 96
Sergii, I took the files into work where I can get shell access on a Unix box and finally managed to get the patches to run - I think it was more a case of user ignorance than anything ;-). I did get a bunch of messages that didn't look too good (see attached file), but I'm not clear if that means that parts of the two patches have failed.
All the files that I was expecting from looking at the patches were updated when I ran them, and I have uploaded them to a test site and I can see that things like the Custom Fields admin page has changed. But where should I find the settings to add specific custom fields to the Edit Captions page?
Thanks, James
Posts: 16
you didn't get any "Chunk ... failed", so the patch was applied correctly. No idea what "missing header" warnings mean, but all chunks apparently were applied successfully.
The changes you should see:
1. On CustomFields admin page a checkbox "Multiple selections allowed"
(that's the first patch)
2. On Edit Captions page you should see custom fields for items.
(that's the second patch)
Posts: 96
After a couple of weeks break I am back looking at this. I *can* see the "Multiple selections allowed" on the admin page, but I *can't* see the custom fields on the Edit Captions page.
At the time I applied the patch I did check that all the files had been modified that should have been, and I have just done a manual check through some of them (e.g. ItemEditCaptions.inc, ItemEditCaptions.tpl & CustomFieldItemEdit.inc) and they appear to have all the latest code when compared to the patch file linked above.
I am a bit stuck as to how to investigate this further. should I just go back to the original gallery code and repatch and re-upload? Or do you think it may be because I am working on Gallery2.2 - has anyone tested it there?
Thanks, James
Posts: 16
Try to reinstall the module or rebuild some caches from the Admin page - I'm far from my gallery now and cannot tell what exactly you need to rebuild. Seems that gallery remembers factories/implementations when a module is installed.
Posts: 96
Sergii, I deleted the cache for everything except thumbnails (the options are
Cached HTML pages
Albums and photo data
Module settings
Theme settings
Smarty templates
Temporary directory)
but nothing seemed to happen. Then I went in and tweaked some of the custom fields and added some new test data to an image and all of a sudden there they were in teh edit captions page. Magic!
Very, very happy, and equally grateful for your help.
Thanks, James
Posts: 344
Is this still doable? I want to edit my custom fields for each photo, but I don't want to have to go to each photo's page and edit the custom fields there. So, I am guessing this module will help me...right?
So, what do I need to do? Do I just follow sprugman's tutorial? *Newbie alert*
Posts: 24
I am trying to implement this on a Gallery2.3 installation. So far I was having some success, until I went to view the ItemEditCaptions page. When using the debugging on I receive a "Notice: Undefined index: plugins in ... ItemEditCaptions.tpl.php." I have tried clearing the cache and adding some text to the custom fields, but nothing displays on the Edit Captions page. I do have the multi select check box on my admin page, and it appears to work. I can check it, save and come back, it's still checked. I'm at the end of my rope here, I can't seem to wrap my head around how gallery works.
Posts: 40
Can someone convert Sergil's patches for Gallery 2.3? Or push me in the right direction?
I would really like to add my custom fields to the bulk edit captions page but can't get any of this code to work. Appreciate any help.