0

I want to show one field (file type) twice in the same content type (without display suite as it breaks my other modules). After a user uploads a pdf and saves this content. I want one link to lead to pdf file for download(which it does) and the other link to show generic file (open a pdf in browser) and i dont know how to do that part (To change widget type). I have searched Drupal Answers and found some clues on how to do this in template.php

function bsthemel_preprocess_field(&$vars) {
 $node = $vars['node'];
     if($vars['element']['#field_name'] == 'field_document_pdf') {

        //code to copy and render this field with different widget (havent figured out how yet)
}

Now i am still new to drupal and can't seem to figure this out. Also what i have found is function hook_field_widget_form_alter but i think this has to be done after the new field is made. Or i might look at this completely wrong. Any help is appriciated

2

The "right" way to add additional elements to a view mode (without using a module like Display Suite or Panelizer to take over view modes) is to use hook_field_extra_fields(): This hook will make your added element visible on the core view mode configuration screen.

If you're new to Drupal it might be easier to go with the preprocess route. But instead of working at the level of template_preprocess_field() you should be working at the level of template_preprocess_node(). The node hook contains the field you want to duplicate. The field hook deals with only one field at a time.

  • This helped me a lot, Thank you for the explaination – MePo Dec 28 '15 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.