So you’re here. Like myself probably stuck developing for Drupal 6. All the modules on-line are for the latest and greatest versions of Drupal and you’re scouring posts from 2009 to try find that deprecated module you really need. Well his post is dedicated to making your life that little bit less painful, because I too feel your pain.
Better debugging with devel
Install subversion(to allow devel to download the firePHP extension code needed).
Make sure drush is installed.
drush dl devel && drush en devel
Enable user permissions for devel
Enable what you need to at http://root_url.com/admin/settings/devel
Install FireBug and FirePHP on firefox and enable the Net Panel in firebug
Checkout watchdog output on firePHP, pretty cool eh?
You can see queries in the sidebar or if you’re logging them, here http://example.com/devel/queries
Directly output to firephp with(alternate WARN with ERROR or INFO):
dfb($foo, ‘probably bad’, FirePHP::WARN);
Drupal Specific Vim Config
I like to keep my vim configurations separate from each other so I don’t end up with huge messy config files with settings overlapping and breaking things. Before I used some shell aliases to alter symlinks to different vim configurations I had. Now, I use vimsauce to manage them. Once you got VimSauce installed(I’d recommend Vundle) create a new Drupal specific sauce with
then edit it with
This project provides vimrc customisations for Drupal-specific editing. Exactly what we need.
To install using drush run this:
drush @none dl vimrc
This should install the file into ~/.drush/vimrc/bundle. Now you need to configure your new vimsauce file to work with the drupal vimrc customisations. The vimrc below should explain things. It’s a merge of the vimsauce default settings, a file I found under ~/.drush/vimrc/examples/vimrc_timplunkett.vim and the pathogen settings.
" End of vimrc-install additions.
" Add vim commands, mappings, functions, etc for this source
let g:current_dir = "~/code/drupal"
exec 'cd ' . g:current_dir
" If using NERDTree:
exec 'NERDTree ' . g:current_dir
" Allow Vim-only settings even if they break vi keybindings.
" Always edit in utf-8:
" Enable filetype detection
filetype plugin on
" General settings
set incsearch "Find as you type
set scrolloff=2 "Number of lines to keep above/below cursor
set number "Show line numbers
set wildmode=longest,list "Complete longest string, then list alternatives
set pastetoggle=<F2> "Toggle paste mode
set fileformats=unix "Use Unix line endings
set history=300 "Number of commands to remember
set showmode "Show whether in Visual, Replace, or Insert Mode
set showmatch "Show matching brackets/parentheses
set backspace=2 "Use standard backspace behavior
set hlsearch "Highlight matches in search
set ruler "Show line and column number
set formatoptions=1 "Don't wrap text after a one-letter word
set linebreak "Break lines when appropriate
" Enforce consistent line endings: if 'ff' is set to "unix" and there are any
" stray '\r' characters at ends of lines, then automatically remove them. See
" $VIMRUNTIME/indent/php.vim .
let PHP_removeCRwhenUnix = 1
" Persistent Undo (vim 7.3 and later)
if exists('&undofile') && !&undofile
" Enable syntax highlighting
if &t_Co > 1
" Custom key mapping
map <S-u> :redo<cr>
map <C-n> :tabn<cr>
map <C-p> :tabp<cr>
" Uncomment the following to have Vim jump to the last position when
" reopening a file
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g'\"" | endif
<h3>Sticking to a Coding Standard</h3>
So I try to always adhere to the coding standard of whatever system I'm using. Typically that's easy but I've found getting my hands on a automated check that ensures my code is up to drupal's standards a little difficult(especially with drupal 6). Firstly you need to install PHP's <a href="http://pear.php.net/package/PHP_CodeSniffer/">codesniffer</a>, which I did using <a href="http://pear.php.net/">PEAR</a>.
sudo pear install PHP_CodeSniffer
In the end I was forced to use a Drupal 7 specific codesniffer. This project has actually been merged into the Coder project but as I’m using Drupal 6, the current version of coder that works with Drupal 6 doesn’t include the codesniffer. So I nabbed the latest standalone version of drupal codesniffer.
I then extract it to my ~/.drush folder and symlink it to where pear has placed php codesniffers various syntax checking config files
sudo ln -sv ~/.drush/drupalcs/Drupal $(pear config-getphp_dir)/PHP/CodeSniffer/Standards
Now, this is the setting that I’ve come across that apparently changes phpcs to use Drupal as the standard which codesniffer adheres to.
" Use drupals codesniffer
let g:syntastic_phpcs_conf=" --standard=Drupal --extensions=php,module,inc,install,test,profile,theme"
I could not get this to work. It simply refused to budge from the standard PSR syntax checker that is the default for PHP codesniffer. I was forced to just set the default to drupal’s.
sudo phpcs --config-set default_standard Drupal
This is a little annoying if you jump between standard PHP projects and Drupal projects, so I added a system command call to my various vim sauces to set php codesniffer to the correct standard. It should bug you to enter a sudo password, but I’d rather that than having to explicitly run these commands.
call system("sudo phpcs --config-set default_standard Drupal")
This post has already gotten very long but I’ll try to write something up on getting unit-testing up and running with Drupal 6 at a later stage. I can attest it is possible, just a bit of a pain in the ass.