0

I've started working on a theme from scratch, I've tried to replace the title of the textfield but when imploding the search variable into search_form, the result is blank. Any error that I could be missing?

`function mytheme_preprocess_search_block_form(&$form) { 
  $form['search'] = array();
  $hidden = array();
// Provide variables named after form keys so themers can print each element independently.
  foreach (element_children($form['form']) as $key) {
     echo $key;
     $type = $form['form'][$key]['#type'];
     echo '__'.$type.'<br />';
     if ($type == 'hidden' || $type == 'token') {
        $hidden[] = drupal_render($form['form'][$key]);
    }
    else {
        if($key == 'search_block_form')
        {
            $form['form'][$key]['#title'] = t('');
            //$form['search'][$key] = drupal_render($form['form'][$key]);
        }
        else
        {
        $form['search'][$key] = drupal_render($form['form'][$key]);
        }
    }
}
// Hidden form elements have no value to themers. No need for separation.
$form['search']['hidden'] = implode($hidden);
// Collect all form elements to make it easier to print the whole form.
$form['search_form'] = implode($form['search']);
 var_dump($form);
 exit;
}`
4

1 回答 1

0

参考http://drupal.org/node/1092122

<?php

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {

  return array(
    'article_node_form' => array(
      'render element' => 'form',
      'template' => 'article-node-form',
      // this will set to module/theme path by default:
      'path' => drupal_get_path('module', 'MYMODULE'),
    ),
  );
}
?>

<?php
/**
 * Preprocessor for theme('article_node_form').
 */
function template_preprocess_article_node_form(&$variables) {

  // nodeformcols is an alternative for this solution.
  if (!module_exists('nodeformcols')) {

    $variables['sidebar'] = array();   // Put taxonomy fields in sidebar.

    $variables['sidebar'][] = $variables['form']['field_tags'];
    hide($variables['form']['field_tags']);

    // Extract the form buttons, and put them in independent variable.
    $variables['buttons'] = $variables['form']['actions'];
    hide($variables['form']['actions']);
  }
}
?>

文章节点form.tpl.php

<?php echo drupal_render_children($form)?>
于 2012-10-18T05:16:35.007 回答