2

I have looked at the docs for 2.6, but am unable to find an explanation for how to set up multiple fieldtypes in a single package. Can anyone enlighten - I really need this ability.

4

Any ft files in the root of your package directory (system/expressionengine/third_party/your_package) will be recognized as part of the package. See P&T's Field Pack for an example.

  • 1
    Thanks Rob - I actually looked at P&T's Field Pack for inspiration, but there is some magic in there that made me think there must be a "how to" somewhere since this was only made possible in 2.6. It would still be helpful to know what made it possible in 2.6 when it was supposedly not possible before.The way I read Peter Lewis' reply, his suggestion is independent of whatever happened in version 2.6. – John de Beer Aug 18 '13 at 13:55
  • 1
    A lot of EE development unfortunately often comes down to just reading the code to see how it works, so that's probably what P&T did. I'm glad you asked this question though, I was wondering about how this works too. – Adrian Macneil Aug 19 '13 at 4:30
3

There is no documentation on this. Think of a fieldtype not as a single input or textfield, but as a single piece of data. So you could build multiple fieldtypes as separate files and folders (and completely different add-ons) or there's a couple of other ways to approach it: either storing the data in channel_data table as delimited or serialized data (for the multiple fields), or building another table that stores the values separately in different columns.

Your single fieldtype class can simply output 2 input boxes in the view (so appearing as two field(types)s):

<input type="text" name="my_field[value1]" id="cart-tax-rate" value="<?= $existingData['my_value1']; ?>" />
<input type="text" name="my_field[value2]" id="cart-tax-rate" value="<?= $existingData['my_value2']; ?>" />

Then your fieldype method to save the data would either serialize it, or delimiter it in some way.

Alternatively, you take the data submitted and store it in your own table using the reference of the entry ID.

Your field type will also need to pull this data on display too (or format it if you chose the first option.

Any data stored in the channel_data table can also be used for searching, so if you do hold the data in your own table, you might want to consider dropping key pieces of data into the native channel_data column for your fieldtype for search purposes.

  • Thanks Peter - very helpful. A pity I can't mark both your and Rob's as accepted answers, because I can certainly use all the approaches in different situations – John de Beer Aug 18 '13 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.