Archive for the ‘Drupal’ Category

03
Mar

One of the easiest ways to get the full path of the current Drupal page is to call Drupal’s url function with following params:

url($_GET['q'], array('absolute' => true));

The fist param $_GET['q'], will give the name of the actions with params  and array(‘absolute’ => true) param will tell the url function to return absolute path of the current page. Try it.

02
Mar

Log in as Admin, click on Administer->Content management->Content, then open your page in edit mode, click on “Printer, e-mail and PDF versions” link, and uncheck the “Show Printer-friendly URLs list” check box. Thats all.

22
Feb

Step1: Create a new action for your custom php file in the _menu function in the drupal module file, just like following:

$items['my_php_page'] = array(
'title' => 'Custom PHP Page'',
'page callback' => '_my_php_pager',
'access arguments' => array('access  content'),
'type' => MENU_CALLBACK,
'file' => 'my_php_page.inc.php',
);

Step2: Create ‘my_php_page.inc.php file and create an empty function like following:

function _my_php_page(){
}

Step 3: Paste your custom php script just below the _my_php_page function (below the closing curly brace).

clear the cache and browse the new action. Thats all!

19
Feb

To create a content in Drupal

step 1)Include cck and filefield to drupal

step 2)Enable cck
Admin->modules->then enable fields Content,filefield,Nodereference,Number,OptionWidget,Text,User referance->then save configuration

step 3)Admin->content management->add contenttype->type details for name,type & submission form settings->save content type

step 4)Admin->contentmanagement->edit->managefields->add new field->eg:Department and its type->save

step 5)if a field with type userreference then create user role
Admin->usermanagement->roles->addrole

Give permissions to the newly created user
Admin->usermanagement->permissions->enable wanted permissions->save permission

step 6)Admin->contentmanagement->edit->managefields->Drag fields in correct position

step 7)create content->new content->type details ->save

18
Feb

Drupal is a free and open source content management system (CMS) written in PHP.It is used as a back-end system for many different types of websites, ranging from small personal blogs to large corporate and political sites, including whitehouse.

The standard release of Drupal, known as Drupal core, contains basic features common to most CMSs. These include the ability to register and maintain individual user accounts within a flexible and rich permission / privilege system, create and manage menus, RSS-feeds, customize page layout, perform logging, and administer the system.

Drupal can run on any computing platform that supports both a web server capable of running PHP and a database (such as MySQL or PostgreSQL) to store content and settings.

Drupal core

Drupal core is the stock installation of Drupal, which can be optionally extended by third party contributions. In Drupal’s default configuration, website content can be contributed by either registered or anonymous users and made accessible to web visitors by a variety of selectable criteria including by date, category, searches, etc.

03
Feb

Hook_menu is a required step for modules wishing to display their own pages, because the process of creating the links also tells Drupal what callback function to use for a given URL. The menu items returned here provide this information to the menu system.

With the below menu definitions, URLs will be interpreted as follows:

If the user accesses http://example.com/?q=foo, then the menu system will first look for a menu item with that path. In this case it will find a match, and execute page_example_foo().

<?php
function page_example_menu() {
$items = array();

// This is the minimum information you can provide for a menu item.

$items[] = array('path' => 'foo',
'title' => 'A Simple foo Example',
'callback' => 'page_example_foo',
'access' => user_access('access foo'));

return $items;
}

function page_example_foo()
{
drupal_set_title("A Simple Title");
drupal_set_message("A Foo Page Message");
return "A Foo Page Example";
}

?>

18
Jan

Found this great post to manage user session auto time-out via Drupal admin area.

http://old.nabble.com/I-am-intersted-in-the-TimeOut-module-tt2800133.html

It was exactly what I was looking for. Nothing fancy. Just specifying the idle session time out for each type of user role. Made a few code tweaks and customized it to work for Drupal 6.x. Simple and effect. Works great for my project and saved me a lot of time!

Please note that the session time out is in seconds!

I have attached the module with this post. Feel free to download and experiment. Let me know your findings too.

sessiontimeout module

,

13
Jan

Open your Drupal project’s sites/all/modules/print/css folder, then open the print.css file, there you can change the format(text color, size, line spacing etc.) of the content.

,

18
Dec
First of all, you have to download jQuery datatable plugin files from following url:http://www.datatables.net.
After that, copy the jquery.dataTables.js and jquery.js files from /media/js/ to your drupal module folder.
Then copy the demo_page.css and demo_table.css files from /media/css to your drupal module folder.
Then open your .module file and include following line in it:
drupal_add_js(drupal_get_path(‘module’, ‘<your module folder name>’) ‘/jquery.js’);
drupal_add_js(drupal_get_path(‘module’, ‘<your module folder name>’) ‘/jquery.dataTables.js’);
drupal_add_css(drupal_get_path(‘module’, ‘<your module folder name>’) .’/demo_page.css’);
drupal_add_css(drupal_get_path(‘module’, ‘<your module folder name>’) .’/demo_table.css’);
After that, you have to create a div and put your table inside the div. Don’t forget to give an id to the div and the table.
Your table must have <thead></thead> tags to include the heading row and <tbody></tbody> to include the data rows. The structure should be like this:
<pre class=”brush:php”><div id=”demo”>
<table cellpadding=”0″ cellspacing=”0″ border=”0″ class=”display” id=”example”>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr class=”gradeX”>
<td>Jack</td>
<td>32</td>
</tr>
<tr class=”gradeC”>
<td>Tom</td>
<td>25</td>
</tr>
</tbody>
</table>
</div>
Also include the following jQuery line to change your table to a data
drupal_add_js(‘$document.ready(function(){
$(“#example”).dataTable();
});’,'inline’);</pre>

09
Nov

Creating a theme for a form in Drupal 6 is slightly different from Drupal 5.

Steps on how to theme a form in Drupal 6:

  1. Register the theme file.
    Use the hook_theme() function to register the theme for  the form. More information on hook_theme() can be got from here: http://api.drupal.org/api/function/hook_theme

    NOTE: myform1_form and myform2_form are the form ids of the forms you want to theme
    function mymodule_theme()
    {
        $themes = array(
            'myform1_form' => array(
                'arguments' => array('form'),
                'function' => 'mytheme_myform1_form',
            ),
            'myform2_form' => array(
                'arguments' => array('form'),
                'function' => 'mytheme_myform2_form',
            ),
        );
        return( $themes );
    }
  2. Define the callback function. Pass parameters to the theme file and render the file.
    function mytheme_ myform1_form($form)
    {
        drupal_add_css(drupal_get_path('module', 'mymodule') .'/mymodule-form.css');
        drupal_add_js(drupal_get_path('module', 'mymodule') .'/mymodule-form.js');
        return theme_render_template(path_to_theme() . '/mytemplate.tpl.php', array('form' => $form));
    }
    NOTE: It is important to pass the form parameter to the template file as array('form' => $form)
    instead of directly passing $form
    For more information on theme_render_template() check this http://api.drupal.org/api/function/theme_render_template/6
  3. Template file.
    <div class="onelinedd">
        	<div class="onedd">
            	<div class="labels">
     		  <div>Form Field 1</div>
     		  <?php echo drupal_render($form['form_field_1']); ?>
     		</div>
            </div>
        	<div class="onedd">
            	<div class="labels">
     		  <div>Form Field 2</div>
     		  <?php echo drupal_render($form['form_field_2']); ?>
     		</div>
            </div>
        	<div class="onedd">
     	  <?php echo drupal_render($form['submit']); ?>
            </div>
        </div>
  4. Clear cache. Admin -> Site Configuration -> Performance -> Clear Cache

I am sure there must be an better way to do this but, after hours of searching and trying this is what worked for me!

Tips on how to theme a form were taken from these links:

http://agaric.com/note/how-theme-drupal-form

http://drupal.org/node/228189

http://api.drupal.org/api/function/hook_theme

http://api.drupal.org/api/function/theme_render_template/6

, , , , ,