0

In my new module I am writing, I am creating a new content type. In this new content type, I want to attach custom fields for a media player: the media player from MediaFront and a File field with a Media File Selector widget type.

As I understand it, these fields are already defined; I just need to create an instance of each field. How do I create an instance of each field, and then configure the extra parameters?

I haven't come across any good tutorials on how to do this.

1

This has been asked before, for a brief example see Clive's answer here. The easiest thing to do is:

  1. create your field and attach it to an entity with the UI logged in at: Admin -> Structure -> Content Types -> Manage Fields
  2. use the code snippet in the below link, supplying your own $entity_type, $field_name and $bundle_name to get the field_create_instance() code outputted directly for you to copy/paste into your modules' hook_install().
  3. ...if you get good enough to know the Drupal Field API to build these $settings and $config arrays for fields without this code snippet -- more power to you .... I still use this code snippet myself, it saves time.

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.