Drupal Module Development

Syndicate content
For assistance with module development.
Updated: 4 min 5 sec ago

jQuery versioning

12 min 10 sec ago

Is it possible, within a javascript file, to do an if based on the current jquery version? like:

if ($.version == '1.2.3') {
  // Drupal 6
}

Thanks!

Categories: Drupal

Organic Group Panel

2 hours 5 min ago

After having configration, og panel will work same like the panel pages. but how mini panels can be created in this way. and how we can show context between different pane in og panels.

Categories: Drupal

Fields in views organized in 3 collums - fieldgroup?

2 hours 10 min ago

Hi all,
I am becomming crazy ....
tried half of the night to solve a big problem: tried to organize 12 fields in a views display in 3 collums. No way found.
Ok, what do I want to do?!

I have 12 fields in a custom node-type. the node-title and some cck-fields.
No I want to output them in a unformatted-row-view with fields in the following order:

field1/1....field4........field7
field1/2....field5/1.....field8
field2.......field5/2.....field9
field3.......field6........field10/1
..............................field10/2
..............................field11
..............................field12

Problem: I need a flow display, as all fields can have one OR more lines!!!

I tried using float, absolute, .... but I can't arrange the fields in a smooth way (gaps between vertical fields, ....)
I thought about using the existing fieldgroup to generate "wraps" for the fields - but can't include them in views ;-(

How could I solve this problem?? Generating an individual views-view-***.tpl.php?

Please help!

Categories: Drupal

Module similar to Token but much simpler with custom replacement evaluating PHP function

5 hours 3 min ago

Hi! I am new to this community.
Drupal is simply incredible I am really amazed!

Purpose: I want all the content published by users (comments, blog post, forum threads, etc) to be modified by my ParseText($content) function before being stored in the database, and to be modified by UnParseText($content) before being show to user for editing. So what I want is quite simple, is to be able to call those two functions, one on save event, and the other before show edit event.

ParseText would analize the content and do some very complex replacements using complex rules, so in this case I think that Token module is not sufficient.

Example: User enters "I like bananas as I am a monkey", however before publishing the string is modified by ParseText() which results in "I like bananas

as I am a monkey". So when the content is published the special formatted text is displayed.

Now when the user goes and clicks on edit, the string "I like bananas

as I am a monkey" saved in database is modified by UnParsetext() and the result is that the user gets to edit "I like bananas as I am a monkey" (original inputted string).

The problem is not about creating ParseText() nor UnParseText() but how to make them run on the appropiate events and modify the content.

read more

Categories: Drupal

CCK Filefield and drupal_execute

6 hours 43 sec ago

Does anyone know how to create a node with a cck filefield using drupal_execute? I have seen some similar examples, but never with filefield itself, and cannot get it to work...
I've tried this, but something's not working: ($v holds the data for the node)
<?php
                $node = array('type' => $node_type, 'name'=>'admin');
                $values["field_foo_upload"] = array();
                $values["field_foo"] = array(
                    array(
                          'description' => $v['original_filename'],
                          'delete' => 0,
                          'list' => 1,
                          'filename' => $v['filename'],
                          'filepath' => $v['filepath'],
                          'filemime' => $v['filemime'],
                          'filesize' => $v['filesize'],
                          'fid' => 'upload',
                          'previous_filepath' => $v['filepath'],
                   ));
                $res = drupal_execute("{$node_type}_node_form", $values, (object) $node);
?>

I've tried mith many combinations similar to this, but never got it to work. Although I've also tried the same approach for imagefield, and it works perfectly... this way:

<?php
$values["field_bar"] = array(
array(
'fid' => 'upload',
'title' => $v['title'],

read more

Categories: Drupal

embedding a form in a node view

Fri, 2008-07-04 06:18

I am writing a module for a custom content type and has built in use of the voting api with some custom voting criteria. When displaying the node I would like to include a few different forms that update the vote associated with that node instead of having the user go the special edit page. The idea is that a user might be able to look at a view of these content types and just go down the list clicking on buttons that cast votes. The problem is that I can't seem to figure out how to get the node id in the form. This value is available when viewing the page by itself from arg(0), but not as a list. In my hook_view() I am adding the form with some code like this:

$node->content['node_form'] = array( '#value' => drupal_get_form('form_name') );

I haven't found anyway to reference the node that was associated with this form so that I can execute the appropriate sql in my hook_submit function.

Any help is appreciated.

Categories: Drupal

ad insertions in Drupal 6... how about some sucess stories

Fri, 2008-07-04 03:00

I am interested in putting some ads in some of my Drupal sites, but not sure what direction to take. I wanted to hear about some success stories before I start. so, any comments on what to do?

Categories: Drupal

user_external_login

Fri, 2008-07-04 01:03

Has anybody else had issues when creating a customised user login module?

I am finding that Drupal is allowing a login (via user_external_login) by users who are blocked. There is a thread here that suggests a reason - but I assume that as it is a year ago the patch has been committed.

Categories: Drupal

Book Module - Adding page number navigation

Thu, 2008-07-03 23:39

For a new 6.2 site, I'm customizing the Book module by maintaining a separate copy of book-navigation.tpl.php in my theme directory. I started by removing the tree and converting the next/previous links into buttons. Because my content can get as big as twenty pages (but more often between 6-12), I would like to include page number navigation as well.

Needless to say, I could create these manually within the nodes, if I really had to. And there are at least a few other module-based solutions for this, but none that would integrate well with my current Views/CCK/Book setup (so far as I can tell).

What I would really like to devise is a way to add a query to book-navigation.tpl.php that grabs the total number of pages at a given book depth and present numerical links to each of those pages.

I note that this has come up before (example), but I'm not sure if anyone has actually addressed it here yet.

Categories: Drupal

open default local task by default

Thu, 2008-07-03 22:49

i want drupal open default local task automaticaly when i click on the parent menu item:
example:
news (parent menu item is a normal item) /news
--overview (default local task) /news/all
--commercial (menu normal item) /news/commercial
--scientific (menu normal item) /news/scientific
but when i click on news link i dont see overview in actived style.

Categories: Drupal

Multiple database query?

Thu, 2008-07-03 22:39

I need to obtain how many threads exist on forum:

function _forumstat_fetch() {
  $sql = "SELECT COUNT(*) AS nthreads FROM {node} WHERE status=1 AND type='forum'";
  $res = db_query($sql);
  $item = db_fetch_object($res);
  return $item;
}

The code work pretty good, I get the number in $item->nthreads;

Now I want to obtain how many post (comments) exist on forum. I need to put a separate SQL query for this purpose? But db_fetch_object($res) accept only one query :(

Someone know which is the best way to solve this problem ? I appreciate any idea! Thanks

Categories: Drupal

Multiple node types specified within one module?

Thu, 2008-07-03 21:42

Hi there. Pardon me if this is a simple question, and my apologies if it's an obvious answer and I'm just missing it in the API, if one has two (or more) node types specified in a module, is it possible to handle the separate node types in the other hooks, such as hook_insert()?

For a more specific example, let's say I have module "Foo" with node types "Foo" and "Bar," where Foo and Bar both have tables reserved for them with extra content. Using the hooks, one can just use the "Foo" module to handle both the "Foo" and "Bar" database inserts, right?

Thanks in advance.

Categories: Drupal

How do I Query a DB and post the results -

Thu, 2008-07-03 21:12

so i have TestMYSQL Query page on my website and i am trying to query and post the results of the role db, and once i can get that figured out - then i can query and post the results of another db I created titled front_page_by_role . This db has the role, description, sort, and include fields.
Basically i have been trying to get a simple query to work before i go and query the other DB. Any Help?
p.s. i see the database's are being queried in modules and such but its hard to pick out the code I need and get it to work.

Categories: Drupal

set form #action in hook_validate?

Thu, 2008-07-03 20:58

I'm finishing a module to capture new customer information for a client. The new cust will fill out the form which includes several taxonomy terms and either email the form to my client and send a check or pay via paypal. The email portion works fine which is handled by myform_submit. For the paypal, I've included paypal's hidden fields in the form and if I set the #action to the paypal url, clicking the pay now button immediately sends me to paypal. What I want is for the pay now to first run thru myform_validate so I can set the hidden fields using form_set_value. My client is selling monthly subcriptions of three types each at a different price and, based on the package selected on the form, I will set the correct price. I have tried to set the #action in myform_validate but it does not work.

If anyone can help me dynamically set the #action or has a suggestion as to how to approach this, I would greatly appreciate it.

Categories: Drupal

Changes in the API with Drupal 5.7 ?

Thu, 2008-07-03 19:45

Hello,

I am working on a Drupal 5.7 installation. I use to work on the first version of Drupal 5 last year and developped some modules.

I get in trouble with the forms. I manage to make the form page but when I submit it, it doesn't perform the actions in the hook_form_submit hook and I get to a blank page. I am wondering if something changed since I worked on the form API or if I'm doing something wrong.

I have something looking like that in the hook_menu :

$items[] = array(
    'path' => 'addforumperso',
    'title' => t('Ajouter un Forum'),
    'callback' => 'drupal_get_form',
    'callback arguments' => 'forumspec_add_form',
    'access' => user_access('administer uieforum'),
    'type' => MENU_NORMAL_ITEM,
);

for the hook_form :

function forumspec_add_form() {
$form['ForumName'] = array(
  '#type' => 'textfield',
  '#title' => t('Sujet'),
  '#size' => 60,
  '#maxlength' => 128,
  '#required' => TRUE,
       );

$form['button'] = array(
  '#type' => 'submit',
  '#value' => t('Envoyer'),
  '#weight' => 19,
);

return $form;

for the hook_form_submit :


function forumspec_add_form_submit($form_id, $form_values) {
drupal_set_message(t('OK'));

read more

Categories: Drupal

Change the content of a comment, how?

Thu, 2008-07-03 19:07

I want to be able to change the actual text of a comment, as it is being sent to the site. I know how to do it with nodes, but when I apply the same principles to comments, it fails.

Here's what I do with my nodes:

1) I hook into form_alter and add my own function to $form['#validate']
2) In that function, I have access to &$form_state. I use the content of $form_state['values']['body'] to work my regex magic and I finish by writing the modified text back into $form_state['values']['body']

The net result is exactly what I'm looking for: if you Preview the node, or Edit it later on, the text box (and Preview) contain the modified text instead of what the author originally typed.

(In case you're wondering, yes, there's a very good reason why a simple text filter isn't enough, but the details would lead us away from the issue at hand.)

Then I found out it doesn't work for comments.

I use the same form_alter hook. I call a separate function for validation. I can find the comment's text in $form_state, but no matter what I do, nothing I do ends up changing the text in the same way that I can with a node...

As far as I can tell, the text of the comment appears in 4 places in the $form_state:
$form_state['values']['comment']
$form_state['buttons']['submit'][0]['#post']['comment']
$form_state['buttons']['button'][0]['#post']['comment']

read more

Categories: Drupal

Reset To Defaults

Thu, 2008-07-03 18:33

Hi, I was just wondering if there was a hook or a custom method in using the "Reset To Defaults" button on forms in the administration section?
The reason why it doesn't work by default is because I'm storing the form data in an individual table rather than storing them in the variables table using variable_set().

So, in conclusion I want to be able to update a database table with default values when "Reset To Defaults" is clicked. The default values will be stored in variables or an array in the actual function.

Categories: Drupal

Retrieve the posted values

Thu, 2008-07-03 18:12

Dear Community,

its already 2 days that I'm trying to figure out how to do the following task and still now I can't solve the problem!

Please, hope some of you can give me some important tips.

I've an XML file with countries, that I fatch without any problem and I show this countries into a form select.

What I want to do it, post the selected value, get in a result page the posted ID and parse anoter XML file to get the righr detail for i.a. a listing of products.

I can't understand how to get the value in a page set to show the listing.

NOTE.
1) I'm using XML becouse I'm going to connect myself to a web service.

2) when I understand all this, the form submission will be more complex because I'm trying to cereate a booking hotel system, so much more parameters like data etc etc as to be sent.

Please, hope someone can give me a help

thanx you

Categories: Drupal

Theming a module

Thu, 2008-07-03 16:10

I have this module:

<?php
/**
* @file
* Obtain forum statistics
*/

/**
* Implementation of hook_block()
*/
function forumstat_block($op = 'list', $delta = 0) {
  switch ($op) {
    case 'list':
    $block[0]["info"] = t('Forum statistics');
    return $block;
   
    case 'view':
    $item = _forumstat_fetch();
    $subject = theme('forumstat_mytheme', 'Forum Statistics');
    $content = theme('forumstat_mytheme', check_plain($item->nid));
    $block["subject"] = $subject;
    $block["content"] = $content;
    return $block;
  }
}

/**
* Fetching statistics from database
*/
function _forumstat_fetch() {
  $sql = "SELECT nid FROM {node} WHERE status=1 AND type='forum' ORDER BY RAND() LIMIT 1";
  $res = db_query($sql);
  $item = db_fetch_object($res);
  return $item;
}

/**
* Implementation of hook_theme()
*/
function forumstat_theme() {
  return array(
    'forumstat_mytheme' => array(
    'template' => 'forumstat_mytheme',
    'arguments' => array('forums' => NULL, 'text' => NULL),
    ),
  );
}

And this is my theme file (forumstat_mytheme.tpl.php):

<table width="100%" border="1">
  <thead>
    <tr>
      <th><?php print $forums; ?></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><?php print $text; ?></td>
    </tr>
  </tbody>
</table>

read more

Categories: Drupal

Where can I hire someone to improve Drupal's comment features

Thu, 2008-07-03 12:18

Where can I go to gather bids for a developer to improve the way Drupal handles comments? I have some very specific ideas for a better UI but I don't have the skills to program them myself.

Categories: Drupal