5

I want to create a custom plugin (element type) that does not allow custom fields. Therefore, when digging through existing element types, do I really need to have the getSources method?

If this is the case, what is the P&T definition of "sources" and are there any base element types that don't use "sources"?

1
  • Maybe the question is more along the lines of what really an Element Type should be? If I need to assign custom fields it should be an element type or if there can be many items of this type? Commented Nov 5, 2014 at 2:53

1 Answer 1

4

Element Types, Custom Fields, and Sources can work closely together, but how you structure that relationship has a lot of flexibility.

Sources are optional. They are a convenient way to group and filter Elements, but they vary in the way that they group those Elements – Globals use Global Sets, Categories use Category Groups, Entries use Sections – and if you don't need them, you should be able to just leave them out altogether.

One place, where sources aren't completely non-existent, but where you will see the Craft user interface present an Element Type without any sources is if you restrict an Asset field to a single folder or an Entry Relations field to a single Section. When you trigger the field modal to select the related Assets or Entries, you will not see any sources in the sidebar, because all the Elements fall into that singular container that you set in the settings.

Building your custom Element without sources would behave in a similar way. Your Element index page and your Element Field Type will expand to full width and your user will just see your content however you wish to present it.

Update

To your question in the comments: What should be an Element Type?

I'm sure this is a much longer discussion, but I will volunteer a vague one sentence answer!: when the benefits of using the extendable features of Element Types (sources, search, relations, etc.) outweigh the costs of developing more specific custom solutions for your needs.

1
  • Thanks Ben, search is the real key here. I want to extend that feature to these types... Hence the decision for the element type. Commented Nov 5, 2014 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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