I felt pretty solid adding them in 6.x, but it seems there are only block and code fields are ported for D7. Am I missing something or are there any suggested workarounds?

Comments

swentel’s picture

Status: Active » Closed (works as designed)

It's supported (but wasn't in ds.api.php, sorry for that, added now) - comment uses it a lot, see ds.ds_fields.info.inc for that, so should work pretty much out of the box.

sleamey’s picture

Status: Closed (works as designed) » Active

Thanks a lot, but the code below doesn't work. What did I forget?

function mytheme_preprocess_taxonomy_term(&$vars) {
  $vars['myfield']="Hello, world!";
}

function mytheme_ds_fields_info($entity_type) {
  $fields = array();
  $fields['myfield'] = array(
    'title' => t('My own preprocess field'),
    'field_type' => DS_FIELD_TYPE_PREPROCESS,
  );
  return array('taxonomy_term' => $fields);
}

Or maybe I initially asked a wrong question? The goal is to add a variable in theme preprocess function and have an ability to manage its display position with DS UI.

In 6.x branch I used to write something like that in template.php:

function mytheme_preprocess_node(&$vars, $hook) {
  $vars['myfield']="Hello, world!";

  if (function_exists('_nd_preprocess_node') && variable_get('nd_preprocess_override', FALSE)) {
    _nd_preprocess_node($vars, $hook);
  }
}

...and then adding a new preprocess field with field key 'myfield' thru UI. The most confusing thing is that "preprocess fields" aren't mentioned anywhere in 7.x UI

swentel’s picture

I'll have to try this out this weekend, maybe there is something strange happening with preprocessing of terms.

sleamey’s picture

One more thing I've noticed: mytheme_ds_fields_info is NEVER called, so it's not a term-specific issue. Does it mean I need to create a module and implement hook_ds_fields_info there instead of a theme?

And one more question: the option to create preprocess fields thru UI is removed by some reason or just not implemented yet?

upd: I moved hook_ds_fields_info from theme to separate module and new fields appeared on 'manage display' pages, now I can rearrange them... but field values don't display for terms (node fields display as expected), moving preprocess function also doesn't help.

Finally it seems we have to separate issues:
1) Inability to create preprocess field without creating a module
2) 'there is something strange happening with preprocessing of terms'

swentel’s picture

Title: Preprocess fields in 7.x: HowTo? » Preprocess fields in 7.x on terms

Preprocess fields can be managed from the UI again. I'll look into the terms problem later this day or week.

swentel’s picture

Status: Active » Fixed

Ok, it was inconsistency in core again re: preprocess variables and the object key name it's passing on. Fixed in dev now. (sorry this took so long, lot's of other things on my mind)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.