I have already searched for information on this topic but I did not find much. I hope I did not overlook something.
My problem is the following: I want to try to write a plugin that lists entries from an external service via API calls. I have already done this in Craft2 with a custom field type (a dropdown-field) that listed all available elements.
Now for Craft3, I want to go one step further and implement a Modal like the AssetPicker where the user can list elements in a table or thumbnail view or even search for one.
Making the API-calls is easy. Nothing to fancy there. However, I struggle with how to integrate it into craft and how to do the templating.
I started with a custom FieldType like I did the last time. However, I am not sure whether it would be better to use an Element Type? As far as I understand, Element Types store their entries in the database, which I do not plan to do, since I access a remote database via an API. I only want to store the item-id in my custom field. On the other hand, I have the feeling that there are already available functions like
Craft.createElementSelectorModal() that implement many functions I need and work great with custom Element Types.
I do not yet totally understand the concepts of element types and field types and how they differ. If you have good sources of documentation, I am also thankful for that, especially information on how to use the ElementSelectorModal. I did not find much information about this.
- Would you suggest using a custom field type or custom element type?
- Is it possible to use custom element types without storing everything in a database?
- Do you have any good resources of information on these topics?
- Do you have good resources of information about the ElemetSelectorModal?
Thank you so much for your help.
If I did overlook an answer to my question, already available on this platform, please feel free to refer to it.
I have read a lot now about modals, for example:
- Is it possible to use the ElementType Modal UI for a custom Field Type Plugin?
- How can my plugin generate a generic modal window in the Control Panel?
- Possible to override Garnish.Modal? [Plugin]
And I found this post, which almost exactly describes my problem: Use Entries fieldtype functionality in plugin populated by REST api data, however, some of the linked entries are not accessible to me and it referred to Craft 2.0, not version 3.
I understand that I can build my own modal using the Garnish-code. However, I would love to use the already existing functionality of the element type-modal. Therefore my question is:
- Is it possible to define a custom element type without a database storage connected to it?
I considered copying all API-results into the database and update it regularly by a cronjob. However, this duplicated the content from the external source which is unnecessary in my eyes. I would rather love to "populate" a custom field type "on the go" by a API-call, without writing it to the database. Is there any way to do this?