Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As I understand it, if I want to create a "preprocess field" programmatically I can do something like this:
function mytheme_preprocess_node(&$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('node' => $fields);
}
But if I want to add a preprocess via the GUI where do I specify the variable name (set in some preprocess function somewhere) that should be used to populate the field. When I go to add a field, I am simply asked what entity type the field should be available to. Am I missing something here??
I suspect I'm just missing something obvious here...
Thanks for your help!!
Comments
Comment #1
swentel CreditAttribution: swentel commentedThere is some info at the top of the form on the preprocess field: 'The machine name of this field must reflect the key in the variables, e.g. "submitted".'
I guess it's a bit confusing here. The machine key of that field must be the key in the preprocess variables. Maybe I should see if I can change the label of the machine field to something more clearer here and not hide it by default.
Comment #2
bleen CreditAttribution: bleen commentedAha ... now I get it.
Yeah, I think changing the label might help ... it also may help to have some text on the "manage display" screen where I thought the "setting" button should be that just indicates, "The preprocess variable name is set to FOO" (or whatever)
Comment #3
swentel CreditAttribution: swentel commentedI had some more thoughts about this, but the problem is that a part of the form is shared by all fields, so I currently left it this way, but I added more help text on the preprocess field at the top. Hope it's clear enough now. Also, adding info on Field UI isn't that simple since I would need to implement a hook for this to just add info, but the icon on the right would do nothing. Hoping to make this a bit clearer in the #1242620: Do not show limit textfield on formatter settings edit issue.
Comment #3.0
swentel CreditAttribution: swentel commentedRevamped issue summary.