1

I have 2 plugins I created that store similar data:

Plugin 1: id, name, panel_id, price

Plugin 2: id, name, test_id, price

I want to attach my plugin data to an entry, and I need to make sure they can only select one Panel or Test. I want to know if there is a way to add them as a source for Entries as a new field. Or can I create a similar custom fieldtype to be used for both plugins and have that kind of validation?

I'm using Craft V2.6

1

You can use a Relation Field for each of your element types and include a custom js rule so if one of them has a value, the other one can't be selected.

The more difficult way would be to extend the field and the ElementSelectModal and the ElementIndex to select multiple element types but this is going to be a little bit more tricky since you'll need a custom controller to fetch all elements and can't rely on the ElementsController

|improve this answer|||||
  • Is there a similar feature on craft 2? – juanmrad Jun 22 '18 at 19:30
  • Yes there is the same field just with slightly different logic – Robin Schambach Jun 22 '18 at 19:53
  • Haven't been able to found the equivalent. – juanmrad Jun 22 '18 at 20:03
  • Take a look at craft/app/fieldtypes/EntriesFieldType and the class it extends – Robin Schambach Jun 22 '18 at 20:12
  • So I create a new FieldType that Extends BaseElementFieldType ? and the class should be on both plugins under the folder fieldtype? something like: Plugin1_TestFieldType and Plugin2_TestFieldType ? – juanmrad Jun 25 '18 at 14:23

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.