Search code examples
phpformsdrupaldrupal-7

How to theme add/edit form for custom content type in drupal 7


I have Drupal 7 site. It has custom content type Product. It has 20 fields. I want to control the UI of the add/edit form for this content type.

I created a module under sites/all/modules.

  • admin_product
    -admin_product.info
    -admin_product.module

-admin_product.module

 <?php
 function admin_product_theme($existing, $type, $theme, $path){
 return array(
'product_node_form' => array(
  'arguments' => array(
      'form' => NULL,
  ),
  'path' => drupal_get_path('theme', 'myTheme').'/templates/forms',
  'template' => 'product-node-form',
  'render element' => 'form',
  )
  );
  }

In the templates - sites/all/themes/myTheme/templates/forms/product-node-form.tpl.php

-product-node-form.tpl.php

 <?php
 echo drupal_render_children($form);
 echo 'hello template';  // just to test
 ?>

The template is not rendered.

How do I control the UI of the form.?

Any help highly appreciated.


Solution

  • I think all you need is Field Group module. With the help of this module you can organize all your fields in groups (i.e. divs, tabs etc.). The rest stuff can be made by CSS.

    Other way is to use hook_form_FORM_ID_alter() hook, or, specifically, hook_form_node_form_alter(), to alter your form.

    Anyway, in Drupal 7 Form API differs from Theme API, and the code you provided just has no sense :) Sorry for this :)