6

I'd like to create a new field type that can be attached to content (ie an article) via the admin interface through 'manage fields' of the content type. I am unsure of the process and required hooks to achieve this.

At this point I'd like the field to be nothing more than a simple text field. So far I have defined the field in:

hook_field_info
hook_field_schema (in .install file)

What other hooks do I need to get this to: a) appear in manage fields options. b) appear in the content editor for the content it has been applied to.

Many thanks

  • It has to be created programmatically, as I guess? – Djouuuuh Dec 11 '14 at 14:26
  • yes. at this point I'm trying to work out a simple example with a text field and then build complexity on top of that once i've got the basics down. – RobotEyes Dec 11 '14 at 14:32
  • Just one more thing, you want it to appear in "manage fields" in "add an existing field" select list or do you want it to be already "assigned" to the content-type but not configured yet or something? – Djouuuuh Dec 11 '14 at 14:55
  • 2
    I think I've found interesting articles about creating your own field type and widget and stuff with field API! clikfocus.com/blog/… and phase2technology.com/blog/compound-fields-in-drupal-7 – Djouuuuh Dec 11 '14 at 15:04
10

When I did this a while ago I adapted the excellent field_example module from the Examples Module which is always the first place to look, as it has a lot of Drupal best practice in it.

As they say in the module comments:

     * Providing a field requires:
     * - Defining a field:
     *   - hook_field_info()
     *   - hook_field_schema()
     *   - hook_field_validate()
     *   - hook_field_is_empty()
     *
     * - Defining a formatter for the field (the portion that outputs the field for
     *   display):
     *   - hook_field_formatter_info()
     *   - hook_field_formatter_view()
     *
     * - Defining a widget for the edit form:
     *   - hook_field_widget_info()
     *   - hook_field_widget_form()

So, not for the faint hearted, but as others have said, all the information is there to get you started.

0

Many blog-tutorials exist that explain step by step how to setup a module that creates a custom field type. Besides the articles that Djouuuh suggests, I think this one exactly describes the (basic) functionallity that you ask (i.e., just a widgit with a text field).

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.