All posts filed under: Drupal

It’s all about drupal coding and whining.

Disable upload and comment for a new content type programmatically

comments 9
Drupal

Following code is useful when installing a module that create a new content type programmatically on Drupal 6.x. Basically, it adds two variables setting default values for comments (core Comment module) and attachments (core Upload module). Code to write on my_funny_module/my_funny_module.install. function my_funny_module_install() { // Disable attachments // Read http://api.drupal.org/api/function/upload_nodeapi/6 on "load" variable_set("upload_my_content_type", 0); // Disable comments for this content type // Read http://api.drupal.org/api/function/comment_form_alter/6 variable_set('comment_my_content_type', COMMENT_NODE_DISABLED); // Install schema as usual (if any) drupal_install_schema('my_funny_module'); } […]

Add CSS style for a block into the same block

Leave a comment
Drupal

This simple code can be pasted into a PHP filtered block (or into a block declared by a module) to set some style from a block into the block container itself. <?php echo 'My block content'; /** Put styles inline on html head**/ drupal_set_html_head('<style type="text/css"> #my-block-id { /* my style*/ } </style> '); ?> This code is placed on html head, applied only to the pages where block appears, without touching css optimization. If you […]

Cron cannot run on Drupal: the drupal_goto() case

Leave a comment
Drupal

Sometimes you want to redirect a page to another on drupal. You can do this using a simple function called drupal_goto(). On few sites I’ve enabled the PHP filter module and then created a new page with PHP code input format with drupal_goto(‘node/2’) to redirect the current page to a specified node. Bad idea. I’ve noticed that, after this change, cron.php operations failed, if you have Search module enabled. On cron new contents are indexed […]

Save user profile on Drupal

Leave a comment
Drupal

Tested on: Drupal 5.x After you have created some user fields through Profile module provided by core, you can have the need to save value into the user object. Here a quick howto to do this. On user creation: /** create user profile ($new_user will be an user object) */ $new_user_array = array ( 'name' => "funnyusername", 'pass' => "MyVerySecurePassword", 'mail' => "info@example.gom", 'status' => 1, # status: active ); $new_user = user_save(NULL, $new_user_array, $category […]

Customize exposed filter on Drupal View

comments 2
Drupal

Tested on: Drupal 5.x Views 1.6 When you have to filter a view by a content type, you have to use Exposed filters. Since default list is somewhat ugly (a select with some elements and CTRL to be pressed) we transform it in simple checkboxes. Copy and paste this code into your template.php: # I use imagecache because on my site is active # and doesn't use hook_form_alter /** Display checkboxes instead select for exposed […]

Set views title dynamically for blocks and pages

Leave a comment
Drupal

Tested on: Drupal 5.x – Views 1.6 Problem: you want to display a taxonomy term name as view title, for block and themes. Solution: On views edit screen, just add to your Argument > Argument handling code: $args[0] = 3; Where 3 is the Term ID you want to display as name. When term name will be updated, view title will be updated too. You haven’t to add other arguments via GUI, just this code.

Drupal page caching

Leave a comment
Drupal

Requisites: Drupal 5.x (patched 6.x version available) Apache webserver (to customize .htaccess) Clean URLs Tested on Drupal 5.x Drupal page caching can be achieved using some contrib modules. I choose Boost, available for drupal 5.x and 6.x (only a 5.x patched version is now available). According to installation instructions, query pages are not cached. Since default pagination rely on query (e.g. frontpage?page=2 to display the third page of home page view “frontpage”) you have to […]