Skip to main content
added 417 characters in body
Source Link
Andy
  • 5k
  • 24
  • 37

Generally speaking you can theme field output like other Drupal output. If you use devel_themerdevel_themer* you can normally see the template used and suggestions available. By default fields use theme('field') which by default has a number of suggestions:

// Add specific suggestions that can override the default implementation.
$variables['theme_hook_suggestions'] = array(
  'field__' . $element['#field_type'],
  'field__' . $element['#field_name'],
  'field__' . $element['#bundle'],
  'field__' . $element['#field_name'] . '__' . $element['#bundle'],
);

For example, the first suggestion allows you to override the template/function used for a particular type of field. In this case we could create MYTHEME_field__addressfield() and it would be used for addressfields only. You can add your own suggestions as well.

There are some field API routes as well though. You can use contrib or custom formatters (some of which in turn provide their own theme functions that you can override). Formatters can have settings that might give the results you want. You can add extra settings with a contrib module if you want to extend a formatter. There are also some field-specific hooks that might be useful:

* As you say devel_themer is heavy. It massively changes the markup, and often messes up your JS. I only ever switch it on when I need it and then switch if off immediately afterwards, YMMV!

Generally speaking you can theme field output like other Drupal output. If you use devel_themer you can normally see the template used and suggestions available. By default fields use theme('field') which by default has a number of suggestions:

// Add specific suggestions that can override the default implementation.
$variables['theme_hook_suggestions'] = array(
  'field__' . $element['#field_type'],
  'field__' . $element['#field_name'],
  'field__' . $element['#bundle'],
  'field__' . $element['#field_name'] . '__' . $element['#bundle'],
);

You can add your own suggestions as well.

There are some field API routes as well though. You can use contrib or custom formatters (some of which in turn provide their own theme functions that you can override). Formatters can have settings that might give the results you want. You can add extra settings with a contrib module if you want to extend a formatter. There are also some field-specific hooks that might be useful:

Generally speaking you can theme field output like other Drupal output. If you use devel_themer* you can normally see the template used and suggestions available. By default fields use theme('field') which by default has a number of suggestions:

// Add specific suggestions that can override the default implementation.
$variables['theme_hook_suggestions'] = array(
  'field__' . $element['#field_type'],
  'field__' . $element['#field_name'],
  'field__' . $element['#bundle'],
  'field__' . $element['#field_name'] . '__' . $element['#bundle'],
);

For example, the first suggestion allows you to override the template/function used for a particular type of field. In this case we could create MYTHEME_field__addressfield() and it would be used for addressfields only. You can add your own suggestions as well.

There are some field API routes as well though. You can use contrib or custom formatters (some of which in turn provide their own theme functions that you can override). Formatters can have settings that might give the results you want. You can add extra settings with a contrib module if you want to extend a formatter. There are also some field-specific hooks that might be useful:

* As you say devel_themer is heavy. It massively changes the markup, and often messes up your JS. I only ever switch it on when I need it and then switch if off immediately afterwards, YMMV!

Source Link
Andy
  • 5k
  • 24
  • 37

Generally speaking you can theme field output like other Drupal output. If you use devel_themer you can normally see the template used and suggestions available. By default fields use theme('field') which by default has a number of suggestions:

// Add specific suggestions that can override the default implementation.
$variables['theme_hook_suggestions'] = array(
  'field__' . $element['#field_type'],
  'field__' . $element['#field_name'],
  'field__' . $element['#bundle'],
  'field__' . $element['#field_name'] . '__' . $element['#bundle'],
);

You can add your own suggestions as well.

There are some field API routes as well though. You can use contrib or custom formatters (some of which in turn provide their own theme functions that you can override). Formatters can have settings that might give the results you want. You can add extra settings with a contrib module if you want to extend a formatter. There are also some field-specific hooks that might be useful: