By nimrod98 on
Hi everyone,
As the title suggests, I am writing a module that I would like to append a voting mechanism to a content type selected by the admin in the settings page. Here's what I have so far:
<?php
/**
* Valid permissions for this module
* @return array An array of valid permissions for the jquery_vote module
*/
function jquery_vote_perm() {
return array('access jquery_vote content', 'administer jquery _vote content', 'create jquery_vote content');
} // function onthisdate_perm()
/* Admin settings */
function jquery_vote_admin() {
$form['jquery_vote_maxdisp'] = array(
'#type' => 'checkboxes',
'#title' => t('Node types to append voting mechanism to'),
'#default_value' => variable_get('onthisdate_maxdisp', 3),
'#description' => t("Select a node content type to append the voting mechanism to."),
'#multiple' => TRUE,
'#default_value' => is_array($field['jquery_vote_maxdisp']) ? $field['jquery_vote_maxdisp'] : array(),
'#options' => array_map('check_plain', node_get_types('names')),
'#required' => FALSE,
);
return system_settings_form($form);
}
//Creates a link to the page on the admin page
function jquery_vote_menu() {
$items = array();
$items['admin/settings/jquery_vote'] = array(
'title' => 'Jquery vote module settings',
'description' => 'Description of your jquery vote settings control',
'page callback' => 'drupal_get_form',
'page arguments' => array('jquery_vote_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items['testpage'] = array(
'title' => 'Jquery test page',
'description' => 'Just a test page',
'page callback' => 'jquery_vote_all',
'access arguments' => array('access jquery_vote content'),
'type' => MENU_CALLBACK
);
return $items;
}
//Creates page that has the voting mechanism
function jquery_vote_all() {
$page_content = '<div id="rating">Container</div>';
return $page_content;
//print_r($page_content);
}
//Adding jquery
function _jquery_vote_js() {
drupal_add_js(<<<EOT
$(document).ready(function() {
//insert custom Jquery code here
}
//Initializing the jquery
function jquery_vote_init() {
_jquery_vote_js();
}
All I managed to do is to create a page called testpage so far that has the line <div id="rating">Container</div>. That triggers my custom jQuery which enables a voting mechanism. Is there a way to append that line to a chosen content type? The settings page (admin/settings/jquery_vote) lists ALL content types, but once selected and submit button is hit, how do I select the content type?
I'm a newbie when it comes to creating modules, and any help is greatly appreciated =). Thanks!!