1

I can't get the theme() function to work. Cleared cache too. If I rename the function to: theme('wow_template', $output') it works but anything other doesn't.

function wow_page() {

    $cloud = 'jqcloud';
    $output = array(
        'form' => drupal_get_form('wow_cake'),
        'words' => _wow_get_words(),
        'view' => 'wall'
    );
    switch ($cloud) {
        case 'jqcloud' :
            drupal_add_js(drupal_get_path('module', 'wow') . '/js/jqcloud-1.0.3.min.js');
            break;

        case 'tagcloud' :
            drupal_add_js(drupal_get_path('module', 'wow') . '/js/jquery.tagcloud.js');
            drupal_add_js('jQuery(document).ready(function ($) {$("#wow-container a").tagcloud({size:{start:20,end:40,unit:"pt"},color:{start:"#133D1D",end:"#5F614F"}});});', 'inline');
            break;
    }

    drupal_add_js(drupal_get_path('module', 'wow') . '/js/jquery.textlimiter.js');
    drupal_add_css('http://ca/' . drupal_get_path('module', 'wow') . '/wow.css', array('type' => 'external'));
    drupal_add_css('http://ca/' . drupal_get_path('module', 'wow') . '/fontkit/stylesheet.css', array('type' => 'external'));
    drupal_add_css('http://fonts.googleapis.com/css?family=Droid+Sans:400,700', array('type' => 'external'));

    return theme('wow_'.$cloud, $output);
}

function wow_page_for_word($word) {

    if ($_POST['word']) {

        $input_string = $_POST['word'];

        $output = array(
            'status' => 'false',
            'content' => array()
        );



        $word = filter_xss(drupal_strip_dangerous_protocols(check_url($_POST['word'])));

        $query = new EntityFieldQuery();
        $query->entityCondition('entity_type', 'node', '=')
                ->propertyCondition('status', 1, '=')
                ->propertyCondition('type', 'wall_of_words', '=')
                ->fieldCondition('body', 'value', '%' . db_like($input_string) . '%', 'LIKE');


        $result = $query->execute();
        if ($result) {
            $output['status'] = 'true';
        }
        $nodes = $result['node'];
        $fields = field_info_instances('node', 'wall_of_words');
        $field_id = $fields['body']['field_id'];
        field_attach_load('node', $nodes, FIELD_LOAD_CURRENT, array('field_id' => $field_id));

        foreach ($nodes as $node) {
            array_push($output['content'], $node->body['und'][0]['value']);
        }
        header('Content-type: application/json');
        echo json_encode($output);
        exit;
    }
}

function wow_cake($form, &$form_state) {

    $form['limitedtextarea'] = array(
        '#name' => 'limitedtextarea',
        '#suffix' => '<div class="buttons">
                        <span class="wow-bottom-line">
                            <span class="count">75</span> Characters remaining </span>
                            </div>',
        '#type' => 'textarea',
        '#resizable' => FALSE,
        '#default_value' => '',
        '#size' => 60,
        '#maxlength' => 500,
        '#required' => TRUE,
        '#attributes' => array(
            'onKeyUp' => 'limitText(this.form.limitedtextarea,this.form.countdown,75);',
            'onKeyDown' => 'limitText(this.form.limitedtextarea,this.form.countdown,75)'
        )
    );

    $form['countdown'] = array(
        '#type' => 'hidden',
        '#value' => 75,
        '#attributes' => array(
            'id' => 'hidden_value',
            'size' => '75',
        )
    );


    $form['buttons']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Send Message'),
    );
    return $form;
}

function wow_cake_validate(&$form, &$form_state) {
    if (empty($form_state['values']['limitedtextarea'])) {
        form_set_error('limitedtextarea', t('Please leave a thank you message in highlighted field below.'));
    } else {

    }
}

function wow_cake_submit(&$form, &$form_state) {

    $title = check_plain($form_state['values']['limitedtextarea']);
    _wow_create_node($title, $title);
}

function _wow_create_node($title = "", $body = "", $language = LANGUAGE_NONE) {
    $node = new stdClass();
    $node->type = 'wall_of_words';
    $node->status = 0;
    $node->promote = 0;
    $node->sticky = 0;
    $node->revision = 0;
    $node->uid = 0;
    $node->language = $language;

    $node->title = $title;
    $node->body[$language][0] = array(
        'value' => $body,
        'format' => 'plain_text',
    );

    if ($node = node_submit($node)) {
        drupal_set_message(t('Thank you for your kind words!'), 'status');
        node_save($node);
    }

    return $node;
}

function _wow_get_words() {
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node', '=')
            ->propertyCondition('status', 1, '=')
            ->propertyCondition('type', 'wall_of_words', '=');
    $result = $query->execute();
    $nodes = $result['node'];

    $fields = field_info_instances('node', 'wall_of_words');
    $field_id = $fields['body']['field_id'];
    field_attach_load('node', $nodes, FIELD_LOAD_CURRENT, array('field_id' => $field_id));
    $wall = '';

    foreach ($nodes as $node) {
        if (!empty($node->body['und']['0']['value'])) {
            $wall .= trim($node->body['und']['0']['value']);
            $wall .= " ";
        }
    }
    if (!empty($wall)) {
        $cloud = explode(" ", $wall);
    }

    return array_count_values($cloud);
}
  • And there's a function called theme_wow_jqcloud() somewhere in your code, along with a declaration of that theme item in hook_theme()? – Clive Mar 25 '13 at 16:03
  • No, not sure... I modified my post with the complete code. – user990717 Mar 25 '13 at 16:06
  • 1
    Anything used with theme(...) has to be defined in hook_theme() - it looks like you haven't implemented that hook yet – Clive Mar 25 '13 at 16:15
  • I actually have the function in another file.. guess I just need to add another entry... argh. – user990717 Mar 25 '13 at 16:19
  • 1
    There's not much point me just giving you a coded solution, as soon as you want to change anything you'll be stuck again. The best thing you can do is read the hook_theme() docs fully and apply what you need to your situation – Clive Mar 25 '13 at 16:22
0

Forgot to modify hook_theme to account for new template files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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