doron
doron

Reputation: 1538

Drupal 7, Creating widget with ImageField and a Textarea

Can anyone help me figure out how can i create a widget(Field API) which will contain an image(i want to to be an ImageField) and a textarea in Drupal 7? Unfortunately i cannot find any tutorial how to do this on google. Thanks!

Upvotes: 3

Views: 7612

Answers (4)

Mark Robson
Mark Robson

Reputation: 1328

Try taking a look at this tutorial. Most other ones the writer concentrates on sounding clever, this one has screenshots and is very clear and concise.

Upvotes: 0

doron
doron

Reputation: 1538

Sorry for not closing this. but the real answer to this is to use Field Collection module - drupal.org/project/field_collection. You add multiple field to this. When i asked this question i was new to D7 and in D6 we had to write this by hand. great module!

Upvotes: 1

Jayjitraj
Jayjitraj

Reputation: 236

you should start from this 2 hook to create the widget. then you should start creating the compound field

hook_field_widget_info() hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)

here are some link to create custom field and widget http://www.phase2technology.com/node/1495/ http://drupal.org/project/dnd_character

Upvotes: 1

Clive
Clive

Reputation: 36956

There's no tutorial as such that I know of, but have a look at the Drupal Examples Module, there's a module within called field_example with all of the info you need.

On a very basic level you want to do this:

  1. Implement hook_field_schema() in your module's .install file to define what columns are going to be held in your field table (probably file ID (fid), alternative text for the image, title text for the image and the contents of the text area in your case).
  2. Implement hook_field_info() to define your field type.
  3. Implement hook_field_is_empty() to provide a way for Drupal to know that a particular instance of a field is empty and can be removed when the entity is saved.
  4. Implement hook_field_formatter_info() to tell Drupal the different ways the content of your field can be displayed.
  5. Implement hook_field_formatter_view to define exactly how those field formatters defined in step 4 will be outputted.
  6. Implement hook_field_widget_info to define the different input widgets for your field.
  7. Implement hook_field_widget_form to define the elements that will make up the widget for your field.

Once you've jumped through all of those hoops (it doesn't actually take that long to implement, most functions are just a few lines of code), enable the module and start adding your new field to entities!

Upvotes: 7

Related Questions