1

Basic Question

In Drupal 7, you can override all the fields of a specific content type by changing the field.tpl.php file name to field--YOUR_CONTENT_TYPE.tpl.php

How can you override the fields that appear on the "node add form" for a content type?


More Info

I am using Drupal Commerce Bulk Product Creation and with this module you create your nodes at yoursite.com/admin/commerce/products/add-bulk/PRODUCT_TYPE.

I want to over-ride the field.tpl.php file for this name, but I am not sure how to do it.

I know you can override the node.tpl.php for this "node add form" by using the following in your template.php file:

function YOURTHEME_theme($existing, $type, $theme, $path) {
    return array(
        'commerce_bpc_create_bulk_form' => array(
            'arguments' => array('form' => NULL),
            'template' => 'templates/add/node--add--bpc',
            'render element' => 'form',
            ),
    );
}

Is there a similar code that can be used to override the field.tpl.php file for this node add form?

1 Answer 1

2

Implement hook_form_alter() or one of its relatives by setting the #theme key of the form elements.

7
  • Thanks! After reading the docs on hook_form_alter(), I think it should be this: function chapel_theme($existing, $type, $theme, $path) { return array( 'FIELD_NAME ' => array( 'arguments' => array('form' => NULL), 'template' => 'templates/add/from', 'render element' => 'form', ), ); } but it doesn't work. Do you know what I am doing wrong?
    – big_smile
    Commented Apr 13, 2012 at 10:23
  • 1
    You return an array. The theme function should return a string.
    – Oswald
    Commented Apr 13, 2012 at 18:27
  • Thanks! This is the code I am using: function MYTHEME_theme($existing, $type, $theme, $path) { return string( 'FIELD_NAME ' => array( 'arguments' => array('form' => NULL), 'template' => 'templates/add/from', 'render element' => 'form', ), ); } . However, it returns an error saying that I have a double error. Thanks for any help you can offer.
    – big_smile
    Commented Apr 14, 2012 at 10:37
  • What's a double error?
    – Oswald
    Commented Apr 16, 2012 at 8:30
  • You should be implementing the hook_form_alter() function, not creating a theme function. You cannot use a template to alter form items, you need to make the changes in PHP.
    – sheena_d
    Commented Apr 18, 2012 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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