Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 944
doron Avatar asked Dec 29 '25 03:12

doron


2 Answers

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!

like image 66
Clive Avatar answered Dec 31 '25 00:12

Clive


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

like image 34
Jayjitraj Avatar answered Dec 31 '25 00:12

Jayjitraj