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.
By big_smile on
I am theming my Drupal forms to make them more user-friendly.
I placed this code in my template.php files to theme the photo order page:
// we register the form to the theme registry
function swb_theme(){
return array(
'photo_product_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'photo_product_node_form',
),
);
}
// we pass variables to the template
function swb_preprocess_photo_product_node_form(&$vars) {
$vars['title'] = drupal_render($vars['form']['title']);
$vars['body'] = drupal_render($vars['form']['body_field']);
unset($form['menu']);
unset($form['author']);
}
...and it works perfectly (I make my modifications in photo_product_node_form.tpl.php).
I am now trying to theme my news from.
The trouble is that if I use the following code, I get an error message saying that I can only declare function swb_theme() once:
// we register the form to the theme registry
function swb_theme(){
return array(
'news_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'news_node_form',
),
);
}
// we pass variables to the template
function swb_preprocess_news_node_form(&$vars) {
$vars['title'] = drupal_render($vars['form']['title']);
$vars['body'] = drupal_render($vars['form']['body_field']);
unset($form['menu']);
unset($form['author']);
}
Question: How can I theme two forms?
Background Information
I tried combing the two swb_theme functions:
function swb_theme(){
return array(
'photo_product_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'photo_product_node_form',
),
);
return array(
'news_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'news_node_form',
),
);
}
However, it only picks up the Photo_Product and the News_node.
Comments
I'm just guessing
I'm just guessing here:
That works!
That works! Thanks!
^_^