Some people, when confronted with a problem, think ``I know, I'll use regular expressions.'' Now they have two problems.
Jeremy John's blog
Print Search Box Form in Template Theme File, Drupal 7
Neither $search_form nor $search_box is available in Zen or, likely, any other themes in Drupal 7. Instead, there's a block.
If you need to print the search box in page.tpl.php, you'll need to render the block and then print it like so:
To break that down, 'search' is the module invoking the block. 'block_view' is the operation we want to call, that is, we want to view the block, and 'form' is the machine name of the block you want to print.
Drupal 7 hook_block changes, with example template module
Drupal seven broke out the old hook_block($op = 'list', $delta = 0, $edit = array()) function, which took an operation as an argument, into four functions, hook_block_info, hook_block_save, hook_b
Views Search by Link Module's URL Title: More Views Hacking
So recently I wanted to filter by URL title, having used it extensively as a text field with an optional link in a site.
The code below is supposed to apply to an exposed Link module field filter in Views. Instead of searching to see if the search string matches the URL, this will match the URL title that was provided.
In the code below, you would replace node_data_{field_publication_author.field_publication_author} with the name of your field, in all places that "field_publication_author" occurs in the below.
Set Sitewide Default Context in Drupal
In Context 3 they removed the sitewide default context, that is, the context that can be set to be enabled when no other context is active. The sitewide context, which is enabled at all times, is still available.
But, in its place, Dev Seed has added a very powerful feature, sneakily powerful, in fact.
You can set a context to be active using another context. Seeming kind of meh? Well, read on. You will soon see, young apprentice, just as I did just earlier today.
First, name all the contexts you DON'T want this context to coincide with in a regularized way, like
Git Access on Drupal: How to Get and Use Git to Start Committing Modules and Patches
Want to contribute back to the Drupal community? Don't be afraid, Git is not as hard as you might think. There are plenty of resources available to those who search. Drupal recently switched over to Git from CVS. Much of the documentation on Drupal.org is out of date, so if you see documentation related to CVS, remember that Drupal now uses Git.
This post will serve as a way of helping you to get involved in the Drupal community and contributing modules back.
Get Git Access
Can't see changes to site in Drupal? Clear the Cache. (or: Everything You Wanted to Know About Caching But Were Afraid to Ask)
Let's say you have a common problem in Drupal, wherein you don't see changes on your site that you've just made. Well, you've come to the right place. This post will give you an introduction to Drupal caching that will have your changes up in no time.
Unversioning the Drupal files directory on subversion: committing a directory without its files
These are the SVN properties that we set for the Drupal files directory. The Drupal files directory needs to exist so that the cache as well as uploaded files can be written there, but versioning all the uploaded files is heavy on resources for little benefit.
Version the directory, but don't version the files our subdirectories within the directory:
svn add --depth empty files
After you commit svn add --depth you use the following to ensure that the files inside aren't accidentally committed
cd to the directory
svn propedit svn:ignore .
Custom CKeditor Classes in Style Dropdown
While looking up how to add custom styles to CKeditor's dropdown, I came across a helpful yet tiny custom module from my friend rootwork.
Turn it on and hack on it to add new styles. You can't add styles to the 'a' tag, FYI, create a style for a span tag instead.
Modify Views SQL Query in Drupal, Restrict View to Search Term
So I wanted to be able to pass a default value to the the Views search filter, to filter by a view by a search term, to display that view in a block.
EDIT: There is an easier way to do this, which renders this whole tutorial useful only for other SQL hijacking. Under Filter, select Node: Body. See screenshot.
I had two options, create a view, create an RSS feed, run it through Yahoo Pipes, and cycle it back through, or modify the views query.
Nodereference Fails to Print Referenced Node
I had a case where CCK nodereference wasn't populating the view field in the array, so I had to check to see if it was empty and then manually populate it.
I leave this code as a gift to posterity.
<?php if ( $speaker_view = $item['view'] ) : ?>
<div class="field-item"><?php print $speaker_view ?></div>
<?php else: ?>
<div class="field-item"><?php print node_view(node_load($item['nid']), TRUE); ?></div>
<?php endif; ?>
<?php } ?>
Tutorial: How to Group Fields in Views With a Div or Span Tag
This is a howto for wrapping a div around a few of your view fields (and not others). This is useful, for instance, for being able to group all one's content so that it floats left but does not float around an image.
EDIT: This technique is a good intro to views templates, however, an easier way exists which seems a little hackish, but would work for many use cases. Thanks to Sr. or Sra. Anonymous.
How to Configure Eclipse PDT with Zend Server Debugger on MAMP for Drupal
Anything involving Eclipse is always epic. First, you have to get your head around what distribution of it to use, as confusing as one's first introduction to Linux distributions (there are different kinds of Linux?).
Next, you have to grok the fact that the Zend Debugger must be installed on your server. In this case, MAMP.
Then, you have to make Eclipse listen to the debugging information being outputted, on the debug port.
Finally, you have to figure out how to use a debugger effectively (not in scope, but careful, debugging will blow your mind).
Drupal Boost Module Caches CSS: Can't Change File After Boost Uninstall
So when working with a dev site, I couldn't figure out why my changes to CSS weren't propagating.
I turned off the boost module, cleared the cache, restarted apache.
Then I realized that Apache must be actually not getting to the file. And the only place to do that in Drupal is the .htaccess file.
Viola! Remove this from your .htaccess:
AddDefaultCharset utf-8
<FilesMatch "(\.html|\.html\.gz)$">
<IfModule mod_headers.c>
Header set Expires "Sun, 19 Nov 1978 05:00:00 GMT"
Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
</IfModule>
</FilesMatch>
<IfModule mod_mime.c>
AddCharset utf-8 .html
AddCharset utf-8 .css
AddCharset utf-8 .js
AddEncoding gzip .gz
</IfModule>
<FilesMatch "(\.html|\.html\.gz)$">
ForceType text/html
</FilesMatch>
<FilesMatch "(\.js|\.js\.gz)$">
ForceType text/javascript
</FilesMatch>
<FilesMatch "(\.css|\.css\.gz)$">
ForceType text/css
</FilesMatch>
# Gzip Cookie Test
RewriteRule boost-gzip-cookie-test\.html cache/perm/boost-gzip-cookie-test\.html\.gz [L,T=text/html]
# GZIP - Cached css & js files
RewriteCond %{HTTP_COOKIE} !(boost-gzip)
RewriteCond %{HTTP:Accept-encoding} !gzip
RewriteRule .* - [S=2]
RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css\.gz -s
RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css\.gz [L,QSA,T=text/css]
RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js\.gz -s
RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js\.gz [L,QSA,T=text/javascript]
# NORMAL - Cached css & js files
RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css -s
RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css [L,QSA,T=text/css]
RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js -s
Run Mac Script on Wake from Sleep: Login to iChat
Having switched to the Mac for my work environment, I missed some of the built in scripting that Linux offers natively. Turns out, the Mac offers this too. There are a few minor hurdles to clear in order to start scripting on the Mac. The trick is the interplay between AppleScripting and shell scripts.
My problem was that iChat wasn't waking up after resume from sleep. You may say, "Use Adium!" But Adium crashes and crashes, and doesn't let me add new contacts. Tried the beta, etc.
So I wrote a script which logs into iChat and sets status to "available" that runs on resume from sleep.
First off, install MacPorts.
Next, sudo port install sleepwatcher
Sleepwatcher is invoked in daemon mode to run a command on wake, sleep, or other things. Check out the man page: man sleepwatcher It's pretty powerful.
In order to find out more about the commands that iChat would accept, I created a shortcut to Applescript editor (it's under Utilities) on the dock, then dragged iChat onto it, which revealed the Applescript Dictionary for that program. I tested this:
#!/bin/sh
osascript -e 'delay 10
tell application "iChat"
log in of service "youruseraccount"
log in of service "yourotheruseraccount"
set the status to available
end tell'
save as /path/to/wake.sh
Now, set up an Applescript to run that script. Paste in this code:
do shell script "/opt/local/sbin/sleepwatcher -w /path/to/wake.sh &> /dev/null &"
Compile it, then save it as an application. This program runs the AppleScript app you've created as an background process and runs the terminal command also. In this way you can add it as a login item.
Go to System Preferences -> Accounts -> Login Items and add it there.
Done. Now, ten seconds after login, iChat will log in and set status to available.
SVN Checkout Fails or Hangs: a Workaround
svn co http://www.mysite
Was giving me errors like
jeremy:.. jeremy$ svn up
svn: Working copy '.' locked
svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)
jeremy:... jeremy$
jeremy:... jeremy$ svn cleanup
svn: In directory 'sites/all/modules/contrib/emfield/contrib/emthumb'
svn: Error processing command 'modify-wcprop' in
'sites/all/modules/contrib/emfield/contrib/emthumb'
svn: 'sites/all/modules/contrib/emfield/contrib/emthumb/CHANGELOG.txt'
is not under version control
jeremy:.. jeremy$
It seemed the that SVN repository (hosted on an external server) was
timing out or something and would fail halfway through the checkout.
So I was able just rsync the file to my machine (tarring and then scp or
rsync failed due to timeouts).
rsync -avz -e ssh youruser@yoursite:/var/www/vhosts/yoursite/trunk
./yoursite
But then svn switch was giving me errors like
jeremy:... jeremy$ svn switch https://myrepo.com
svn: 'file:///repo_hosted_on_server'
is not the same repository as
'https://myrepo.com'
So this was the solution:
svn switch --relocate repo_hosted_on_server
https://myrepo.com





