Just got a DatabaseSchemaObjectExistsException when activating a module ? the solution is to call uninstall the shema with the php command :

drupal_uninstall_schema('module name');

You may need after that the command

drupal_install_schema('module_name');

Here is a boilerplate for Drupal 7, for the admin configuration feature of 'mymodule', accessible by the user having the 'administer mymodule' rights,  and shows the use of functions variable_get() and system_settings_form()

First, add the admin page entry in the HOOK_menu in your module.php file. This will create a menu item to the administration page we set to "admin/config/system/mymodule". The actual code for the admin page will be in a separated file called mymodule.admin.php. That way, the php for the admin page is only loaded when actually accessing the page, saving ressources on the webserver.

function mymodule_menu() {
	$items['admin/config/system/mymodule'] = array(
		'title' => 'Mymodule configuration',
		'page callback' => 'drupal_get_form',
		'page arguments' => array('mymodule_admin'),
		'file'  => 'mymodule.admin.inc',
		'description' => 'Configuration for mymodule',
		'access arguments' => array('administer mymodule'),
		'type' => MENU_NORMAL_ITEM,
	  );
	return $items;
}
	

Then add the path of the admin page to the .info file of your module so that a nice "Configure" button shows for your module on the admin module management page.

configure = admin/config/system/mymodule

 Back in the mymodule file, we need to declare the access key 'administer mymodule' with the HOOK_permission

function mymodule_permission() {
  return array(
    'administer mymodule' => array(
      'title' => t('Mymodule administration page'),
    ),
  );
}

Now we need to create the "mymodule.admin.inc" file, in the same directory as "mymodule.php" and start building our form

function mymodule_admin($form, &$form_state){

  $form['mymodule_something'] = array(
    '#type' => 'textfield',
    '#title' => t('A very important string'),
    '#default_value' => variable_get('mymodule_something', 'default value'),
    '#size' => 32,
    '#maxlength' => 64,
    '#required' => TRUE,
  );

  return system_settings_form($form);
}

We system_settings_form function takes care or the submit, and the action button, meaning we are done here. We can now use "variable_get('mymodule_something','default value')" in our mymodule module and get what evere value the user set.

On last thing is to delete our variable when uninstalling mymodule with the HOOK_uninstall() in your mymodule.install file

function mymodule_uninstall() {
  variable_del('mymodule_something');
}

 

When you want to refresh your dev environement with data from the production, you need to update the database and the user uploaded files, with is the most boring part if you only use FTP.

You can avoid this step by adding a single line to your htaccess file, or even better, in the virtualhost definition to avoid drupal overriding it on every update.

RewriteRule ^sites/default/files/(.*)\.(jpg|JPG|png)$ https://productionsite.com/sites/default/files/$1.$2 [QSA,R=301,NC,L]

 

You cannot translatea view's title out of the box.
There is howewer a simple solution

In your module, juste use this code, and every views title will then be translatable :

function MODULE_views_pre_render(&$view)  {
  $view->set_title(t($view->get_title()));
}

or in your theme's template.php file : 

function THEME_views_pre_render(&$view)  {
  $view->set_title(t($view->get_title()));
}

In Drupal 6 and 7, user using the password recovery, or "verify your email" registration process, will receive a mail with a one time login link.
Cliking the link will bring them to a one time login form they have to submit.

So here is a trick from sivaji from drupalgardens to bypass the one time login form.

On the mail template, found in drupal 7 on the account admin page ( admin/config/people/accounts ) add after [user:one-time-login-url] token "/login" so you have "[user:one-time-login-url]/login".

For Drupal 6 it will be "!login_url/login"

This will just do the trick !

 

Having fun with Sencha Touch and Drupal Views ? Sencha provides a nice list paging plugin than makes infinite scrool list in no time.

But a problem appears when you want to plug this with Drupal views , using the Views Datasource module to output the json. Because the Sencha Touch pager will request the next page using a 1 based index, when Views use a 0 based index.

To fix this, you need to rewrite the way the Sencha Touch Proxy build its GET request :

Ext.define('path.proxy.MyProxy', {
    extend: 'Ext.data.proxy.JsonP',
    alias: 'proxy.myproxy',
    xtype : 'drupalpagerjsonp',
    config: {
        // This is the url we always query
        url: 'http://my/view/outputing/json/page',
        
        reader: {
            type: 'json',
            rootProperty: 'nodes'
        }
    },
       
     /**
     * We need to add a slight customization to buildRequest
     * We change the 1 index based page query to a zero based one
     */
    buildRequest: function(operation) {
        var request = this.callParent(arguments),
            params  = request.getParams();

        Ext.apply(params, {
            rpp: operation.getLimit(),
            page: operation.getPage() - 1
        });
        
        request.setParams(params);
        request.setUrl(this._url);

        // As we're modifiying the request params, we need to regenerate the url now
        request.setUrl(this.buildUrl(request));
        
        return request;
    }
});

And that is it !

Everything you need to know can be found on drupal.org at http://drupal.org/node/180528

Silvio Gutierrez explains why the default views pager is really bad ( run the query once for data, and an other time to count ..) but also how to very easyli fix this problem with the lite pager module.

Add two tips on how to fix left joins when you do not need it, and avoid distinct in queries, and you are set.

So lets dive and learn how to optimise Drupal views the right way in 3 easy steps.

Drupal can cache content using  "php static", writing in the database or writing in the filesystem.

Lullabot has a full article about it  A Beginner's Guide to Caching Data in Drupal 7 that explains all that you need to know for a clever day to day developpement.

Your site offers a big list of summarized contents, but you dont want the user to click, wait for loading, then go back to the list page losing where they were. So let them have a quick preview but showing them the full content ( or just a little more ) using a lightbox style overlay.

The most efficient solution right now, is to use the colorbox module  with the colorbox node module , the last one beeing the one doing the magic.

Integrated with views

Colorbox node is integrated with views and extends the option "link this field to the original piece of content" offering a new checkbox to "Display the content inside of a colorbox", and height / width parameters. Just plug and play.

Placed on a link manually

By just adding the class "colorbox-node" to any internal link, will open the supported content in a colorbox

<a class="colorbox-node" href="blogs/my-example?width=600&height=600">My Example</a>

Pages