0

In Drupal 7. I have the following code in my template.php file:

function mytheme_theme($existing, $type, $theme, $path) {
   return array(
   'comment_form' => array(
   'render element' => 'form',
   ),
 );
}

I also would like to use the following code to theme the Register page:

function mytheme_theme() {
  $items = array();
    $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'mytheme') . '/templates',
    'template' => 'user-register-form',
    'preprocess functions' => array(
       'mytheme_preprocess_user_register_form'
    ),
   );
 return $items;
}

How do I merge the two snippets of code?

Any help on this is greatly appreciated. :)

  • Welcome to Drupal Answers! Merging two PHP arrays is a plain PHP question; nothing in Drupal changes the way array can be merged. – kiamlaluno Apr 21 '15 at 7:41
2

@duru's answer will work, but is needlessly complex and makes it difficult to see the structure of the returned array. This is equivalent:

function mytheme_theme($existing, $type, $theme, $path) {
  return array(
    'user_register_form' => array(
      'render element' => 'form',
      'path' => drupal_get_path('theme', 'mytheme') . '/templates',
      'template' => 'user-register-form',
      'preprocess functions' => array(
        'mytheme_preprocess_user_register_form'
      )
    ),
    'comment_form' => array(
      'render element' => 'form',
    )
  );
}
| improve this answer | |
3

Just merge like:

function mytheme_theme($existing, $type, $theme, $path) {
  $items = array();
    $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'mytheme') . '/templates',
    'template' => 'user-register-form',
    'preprocess functions' => array(
       'mytheme_preprocess_user_register_form'
    ),
   );
   $items['comment_form'] = array(
    'render element' => 'form',
    ),
   );
 return $items;
}
| improve this answer | |
  • You welcome. :) – duru Apr 19 '15 at 17:30

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