简体   繁体   中英

Drupal 7 - node Form template is not used

I have a Problem with one node type and it's form. I want to alter it with an template file. I already did this with another node type on my drupal site and this worked, but it doesn't work for this second type.

So (as I did for the other node type) I placed this hook in my module:

function MY_MODULE_theme($existing, $type, $theme, $path) {
  return array(
    'FORM_ID' => array(
      'arguments' => array(
          'form' => NULL,
      ),
      'render element' => 'form',
      'template' => 'TYPE-node-form',
      'path' => drupal_get_path('module', 'MY_MODULE'),
    ),

  );
}

And also declared this function (in my module):

function template_preprocess_TYPE_node_form(&$variables) {
   /* Some hide(elements) and stuff */
}

And of course, I created the file TYPE-node-form.tpl.php in the module directory

/* Something */
TEST
    <?php if($form): ?>
      <?php print drupal_render_children($form); ?>
    <?php endif; ?>
/* Something more */

But it does not load this template ( I cannot see TEST and the other things). Also after multiply times of clearing cache and refreshing.

With DisplaySuite I was able to set a template in the backend (Administration » Structure » Content types » TYPE » Manage fields). But I want to have my own template file (and also not located in the sites/all/modules/ds/layout/.. folder). Deactivating DisplaySuite also does not do the trick. I also looked tried to place the MY_THEME_theme() code into the template.php file of the administrator theme, but it also did not work.

Any suggestions? What can I do? Is there a way to find out which template is used or where it is overwritten? I have read that Themes overwrite modules templates declaration?!

If you are using D7, hook_theme implementations do not have 'arguments' key, but 'variables' .

Also in this case remove the 'arguments' or 'variables' key in order for the 'render element' to work. Hope this helps.

Final code:

function MY_MODULE_theme($existing, $type, $theme, $path) {
   return array(
     'FORM_ID' => array(
        'render element' => 'form',
        'template' => 'TYPE-node-form',
        'path' => drupal_get_path('module', 'MY_MODULE'),
     ),
   );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM