drupal developer

Deploying Drupal projects: git + capistrano

 

removing some folders from git, file .gitignore with these contents:

 

# Ignore paths that contain generated content.

cache/

files/

sites/*/files

sites/*/private

 

 

 

Using symbolic links for /files directory:

 

 

namespace:custom do

    task:symlink do

      run "ln -s /var/www/crucerista/sites/crucerista.net/files/ /var/www/crsta/current/sites/crucerista.net/"

      run "echo 'finished'"

    end

end

after "deploy","custom:symlink"

 

 

Related links:

Similar technique, but aplied to Rails apps: http://www.practicalecommerce.com/blogs/post/468-Creating-Symlinks-When-Deploying-a-Rails-Application

Another idea, File Transfer actions in Capistrano: http://www.simonecarletti.com/blog/2009/02/capistrano-uploads-folder/

 

Howto patch a Drupal module

Some contributtion to add to this Drupal module with which you have been working on?

Very easy, take note:

 

  1. Go to the folder of your module, previously cloned with git. For example, my contribution this morning: 
  2. git clone --recursive --branch 7.x-1.x http://git.drupal.org/project/cpn.git
  3. cd cpn
  4. Create a new branch, for example: git branch 1912834-weight
  5. Change to this branch to make the changes: git checkout 1912834-weight
  6. Make your changes
  7. Add them with: git add your-file-modified
  8. Commit them, git commit -m "comment your changes as much as possible"
  9. Create your new patch: git diff 7.x-1.x > cpn-weightsettings-1912834.patch
  10. That's it :-)

 

More info:

 

 

Howto contributing a module to Drupal

 

,

 

  1. Think in some interesting project, and build your module,
  2. If you didn't, create a Drupal user, and a new sandbox for your module(s). Follow this instructions and commit your first lines of code http://drupal.org/node/1068950
  3. Work in your project, and when you are happy to publish your first stable release, go to the next step.
  4. Help the community, doing some reviews of other modules (3 at least): http://drupal.org/project/issues/search/projectapplications?status[]=2&status[]=7 (more info here: http://drupal.org/node/1410826)
  5. Create a new project aplication: http://drupal.org/project/issues/projectapplications

 

 

 

 

Drupal developer in London

My name is Alejandro Moreno Lopez. I'm an spanish developer living in London, degree in Computer Science, who has specialized in PHP and Drupal development.

 

Debug Cron white screen in drupal

Debugging cron issues and errors is one of the most tricky things in Drupal. If you are dealing with a big site, with people adding nodes, inserting content which you can't allways force to be commited in the right way, and things like that, it is not unusual to find a cron broken by some "misterious" node.

Well, it is quite easy to find this "misterious" offender, just logging the cron activity. How, very easy, with my new module "cron_killing_finder".

It is published in my "Drupal SandBox": http://drupal.org/sandbox/programadoresweb/1895746

Just download it and follow the really simple instructions:

"Just activate it and go to /admin/reports/dblog. You'll find a "Node hook update_index: NID" string with the cron executions which tells you in last term which node is executed each time. If cron breaks, the last node reflected in the log will be the offender node, very simple :-)."

Hopefully it will be a new "complete" project, so you'll don't have to use git to download it.

Validation file in Drupal without theme / template

 

Sometimes you need to upload files to, for example, validate an affiliate with whom you want to start to work.

The problem, is that these affiliate files need to be "clean", no template, no theme, just the code or validation string which they send.

The solution can be very complicated, like creating a new theme just for a group or a contect of pages... or as simple as creating a node with the string which we need and executing a php code with an exit command. Something like this:

 

valicationStringLikeUZasdBNf6asdfT2asdfafjpdadf===58QYg==

<?php

exit;

?>

 

so, when you open this node, you'll see a blank page like the one in the screenshot.

Well, i don't like to use php inside nodes, this practice must be avoided, but for this case, the code is enough simple and, the most important thing, it doesn't break the cron execution. So, everyone happy :-).

Do you have a different or improved idea for this? Please, share :-)

 

Get Drupal fields for a particular content type

 

Sometimes in Drupal you need to get the fields for a particular content types. 

"$type = 'mytype';

$fields = content_fields();

$type_fields = array();

foreach ($fields as $field_name => $field_data)

{

  if ($field_data['type_name'] == $type)

  {

    $type_fields[$field_name] = $field_data;

  }

}"

 

in drupal7 is easier, since we have a direct function:

field_info_instances($entity_type = NULL, $bundle_name = NULL)

 

 

get current drupal theme

very simple:

        global $theme_key;

      echo $theme_key;

 

if we need more information, we can use this:

       $themes = list_themes();

       $theme_object = $themes[$theme_key];

 

        // print all the object fields

       var_dump($theme_object);

 

via http://drupal.org/node/46961#comment-88354

paging results in Drupal

Paginating the results in Drupal is incredible incredible easy. You just have to remember the two "magic functions":

 

  • pager_query($sql, $count);
  • theme('pager',10);

 

pager_query substitutes the typical db_query. Just something like that: 

 

  • // $resource = db_query($sql);  // -> old sentence without pager
  • $resource = pager_query($sql, $count); // -> pager

 

Then, we simple come back to the function that is called by our hook_menu, and we change:

  • return theme('list_products')

with

  • return theme('list_products') . theme('pager',10);

 

It couldn't be easier, could it? :-). In fact it is harder to undertand the documentation and the different howtos and tutorials which you can find than the process itself.

Theming you module

Docs are not allways the best part in programming languages, frameworks or CMS. Sometimes you try to make something and you find problems, just because poor documentation.

It's my situation just now. I was trying to create tpl.php files for a module, and it is really easy... if you follow exactly all the steps.

First, hook_menu:

 

 

/**

 * Implements hook_menu().

 */

function mymodule_menu() {

$items = array();

 

/*

* Category reviews section 

*/

$items['reviews'] = array(

'title'             => 'Bounty reviews',

'description'       => 'Show review categories.',

'page callback'     => 'listofProducts',

  'page arguments'    => array('bounty_settings'),

'access callback'   => 'user_access',

'access arguments'  => array('administer site configuration'),

'type'              => MENU_NORMAL_ITEM,

'file'              => 'includes/bounty_reviews.inc',

);

 

return $items;

}

 

 

Secondly, you could think that just creating the listofProducts should be enought. Well, not at all, you need the theme hook, to show the content using the tpl.php of you choose:

 

/**

 * Implements hook_theme().

 */

function mymodule_theme($existing, $type, $theme, $path){

$path = drupal_get_path('module', 'mymodule'); // . '/templates';

// ADD THE templates DIRECTORY

$path = $path . '/templates'; 

return array(

// as in 'theme('verbose_method',...)

'main_reviews' => array(

'template' => 'main_page_reviews',

'path' => $path,

'variables' => array('forums' => NULL, 'topics' => NULL,'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),

),

//...

);

}

 

And, ending with the magic:

 

/**

 * List of  reviewable products

 *

 */

function listofProducts(){

$output = theme('list_products');

return $output;

}

That's all. If you forget the _theme hook you can be struggling for hours, just receiving a beauty WSOD (White Screen Of the Death) and no more information.

You wellcome :-).