Hacking Drupal Core: Why and How<br />Ashok Modi – June 28, 2011<br />
Why? What about “Don’t Hack Core!”<br />Contrary to what some people say, Drupal is not a one size fits all Swiss Army knife.<br />Not all uses cases can be accounted for.<br />Flexibility does come at a cost.<br />Usually performance.<br />Have you used Pressflow?<br />Some very popular modules justdon’t get maintained.<br />
Examples<br />User Module<br />On user registration, wanted a way to generate simpler random passwords.<br />Drupal (core or otherwise) does not provide any way to override the complex passwords it generates.<br />No choice but to ‘alter’ (hack) core.<br />Another issue involved bad performance on user login (without a patch – Pressflow has a variant but Drupal 6.x still slow).<br />Comment module<br />No index on the user id.<br />Another module using the comment module referencing the user id made it very slow.<br />No choice but to ‘alter’ (hack) the indexes made by core.<br />
Best practices<br />Check the issue queue!<br />If its in there, try and work towards a patch.<br />Use that patch until its part of the project. <br />Otherwise, create an issue if its something that could benefit rest of Drupal and work towards a patch.<br />
Best Practices (cont’d)<br />Very simple<br />Copy the module you want to override into your sites/all directory.<br />Recommend creating a new directory called ‘core_modified’.<br />Similarly for contrib, have a directory called ‘contrib_modified’.<br />Add any changes you make into a patch file.<br />Use diff on the command line or a program like Diffmerge (OSX) or winmerge (Windows) or Guiffy (all).<br />Commit the patch file to your codebase.<br />Will allow you to merge your changes anytime module gets updated.<br />Once things in the affected module are officially fixed, you can move back to the core version.<br />
DEMO<br />Going to go over image module change<br />http://drupal.org/node/1015916<br />If you try to enter data longer than 128 characters, site dies.<br />Don’t know if the patch will get accepted.<br />Lets dive in.<br />
Questions?<br />Have fun hacking Drupal Core and Contrib! ^_~<br />
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.