I'm trying to add a table to the add/edit form of my custom node but I just cant get drupal to even use the theme function.

The node type is called "survey" and uses the default hook_form to create its add/edit form;

The hook_form:

function survey_form(&$node, $form_state) {
    $form['title'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
        '#default_value' => $node->title,
    );

    $form['body'] = array(
        '#type' => 'textarea',
        '#title' => t('Description'),
        '#default_value' => $node->body,
        '#description' => t('Here you can tell users what the survey is about.'),
    );

    //Set the form elements so we can use them to create a table later
    $form['survey_elements'] = _survey_elements_tree_form($node->elements);

    return $form;
}

The hook_theme:

function survey_theme($existing, $type, $theme, $path) {
    return array(
        'survey_form' => array(
            'arguments' => array('form' => NULL),
            'function' => 'theme_survey_form', //also tried 'survey_form'
        ),
    );
}

The the theme function:

function theme_survey_form($form) {
    //Do stuff very similar to theme_menu_overview_form()
    
    return $output;
}

When I replace $output to see if the function is even called I dont see any change.

Does anyone know what I'm doing wrong?

Comments

jaypan’s picture

You have to add #theme to your $form definition somewhere so that it knows to use the theme.

Contact me to contract me for D7 -> D10/11 migrations.

just_fixed_it’s picture

clear the cache?

prakashp’s picture

/**
 * Implementation of hook_theme().
 */
function survey_theme($existing, $type, $theme, $path) {
  return array(
    'survey_node_form' => array(
      'arguments' => array('form' => NULL),
    ),
  );
}

/**
 * Theme function for survey node form.
 */
function theme_survey_node_form($form) {
  //Do stuff very similar to theme_menu_overview_form()

  $output = 'CUSTOM THEME FUNCTION FOR SURVEY NODE FORM';
  $output .= drupal_render($form);

  return $output;
}