Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-10-19 14:48:32

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

Extending Images or other best practices

When you write a plugin, that wants to extend something like Images, for example add more meta data or new data. Would you add more fields or create a new table specifically for the task? Whats the general best practice for this?

Thanks
Rich

Offline

#2 2016-10-19 15:27:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,785
Website

Re: Extending Images or other best practices

It largely depends what you want to do with it.

If you’d like people to be able to edit it, but don’t want to display it in the table on the Image list panel, you might as well add it to the txp_image table directly. If you then hook into the Edit panel callback (more specifically the pluggable_ui() call for extend_detail, and the save step) you can render input boxes so that people can change the data and package it all up for saving alongside the core image data. Any public tags will of course be supplemental to this.

If, however, you intend to offer a different workflow or wish to show the extra data in a tabular format or some other presentation format, you have more choice. You can either add the fields to the current table and just write an admin screen under Extensions to manage it. Or add the fields to a new table keyed off the original image ID. There’s not much in it, but managing your own table is probably more code.

Bear in mind if you do the latter you need to be careful to stay in step with deletions from the Images panel, so that rows in your companion table can be deleted too. This is what smd_bio does. If you keep everything in the same table you get deletion for free, which may (or may not) be what you want.

Not sure if that helps!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2016-10-19 15:42:52

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

Re: Extending Images or other best practices

@bloke
So I think based on your answer, I want to edit the txp_image table directly. I taking the uploaded image and sending to a CDN, and saving the resulting URL. I will show it for reference, but use the image ID to reference it on the front end which I think will make the usage work nice. I won’t have to worry about deleting anything else in this manner too.

Thank you
Rich

Offline

#4 2016-10-19 15:59:51

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,548
Website

Re: Extending Images or other best practices

Rich, maybe this mini plugin is of help?


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB