Fantastic guide at http://dtek.net/blog/extending-drupals-context-module-custom-condition-based-field-value on how to write a context condition for drupal.
I came across an issue the other day when I was working on The Band Company website that required me to order a taxonomy numerically. The issue was, that even though the items that I was ordering were numbers, they were being ordered alphabetically. This is what I did to solve the issue.
This is the album that I am spending most of my time coding to at the moment. Enjoy.
I came across an issue recently with a Drupal installation that I am working on that required me to use hook_views_default_views_alter, and found that the help out there was minimal. I finally got what I was after working, but with much debugging using the Devel module and dpm. I thought that I would put down what I found out to help others in a similar position. Continue reading “Using Drupal’s hook_views_default_views_alter”
As with most developers, I like to listen to music whilst I code. The one that I have been listening to the most at the moment is Don’t Look Now by Way Out West. Check it out on Spotify below.
Its basically a chilled out techno, dance music style album, not too dis-similar to Chicane. Good for getting in the zone and coding too – nothing too distracting going on.
I just wanted to link you into this video from Etsy. Well worth a watch.[youtube http://www.youtube.com/watch?v=22EECFEk9Xs]
One thing that can be difficult to test is email, get it wrong and at worst you can end up sending confusing and misleading emails to your clients. Its easy to get a webserver and a local copy of the database set up, but what about a local email server.
One approach is to create your own mail function, which looks at a system environment to see if it should actually send the mail or not. For instance, if it is a dev machine, ignore the mail function and write the contents of the email to log. This is OK, but it doesn’t actually test the email function until it is on live, which is arguably too late.
I have just come across a package called Dumbster. It is a java application that will sit and respond to SMTP requests, but instead of sending the email on to the recipient it holds on to it in an internal store. Bingo, we are actually testing the mail function, but the email is being contained.
To get up and running you will need Java, and Ant, and a copy of the source code. Extract the files and open up a terminal in the folder you placed the source. Run ant and you should see something like this.
$ ant Buildfile: /home/ubuntu/rjo1970-dumbster-d20b4e6/build.xml clean: [delete] Deleting directory /home/ubuntu/rjo1970-dumbster-d20b4e6/build init: [mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/classes [mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test [mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test/report compile: [javac] Compiling 29 source files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/classes jar: [jar] Building jar: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/dumbster.jar compile-tests: [javac] Compiling 6 source files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test test: [cobertura-instrument] Cobertura 220.127.116.11 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file [cobertura-instrument] Instrumenting 29 files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/instrumented [cobertura-instrument] Cobertura: Saved information on 29 classes. [cobertura-instrument] Instrument time: 174ms [junit] Running com.dumbster.smtp.MailMessageTest [junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.181 sec [junit] Flushing results... [junit] Flushing results done [junit] Cobertura: Loaded information on 29 classes. [junit] Cobertura: Saved information on 29 classes. [junit] Running com.dumbster.smtp.RequestTest [junit] Tests run: 38, Failures: 0, Errors: 0, Time elapsed: 0.079 sec [junit] Flushing results... [junit] Flushing results done [junit] Cobertura: Loaded information on 29 classes. [junit] Cobertura: Saved information on 29 classes. [junit] Running com.dumbster.smtp.RollingMailStoreTest [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.049 sec [junit] Flushing results... [junit] Flushing results done [junit] Cobertura: Loaded information on 29 classes. [junit] Cobertura: Saved information on 29 classes. [junit] Running com.dumbster.smtp.SmtpServerTest [junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 1.113 sec [junit] Flushing results... [junit] Flushing results done [junit] Cobertura: Loaded information on 29 classes. [junit] Cobertura: Saved information on 29 classes. [junit] Running com.dumbster.smtp.SmtpStateTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.038 sec [junit] Flushing results... [junit] Flushing results done [junit] Cobertura: Loaded information on 29 classes. [junit] Cobertura: Saved information on 29 classes. [junitreport] Processing /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test/report/TESTS-TestSuites.xml to /tmp/null279172976 [junitreport] Loading stylesheet jar:file:/usr/share/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] Transform time: 701ms [junitreport] Deleting: /tmp/null279172976 [cobertura-report] Cobertura 18.104.22.168 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file [cobertura-report] Cobertura: Loaded information on 29 classes. [cobertura-report] Report time: 237ms BUILD SUCCESSFUL Total time: 10 seconds
You have now compiled the Java, and to run it use the following
java -jar build/dumbster.jar [PORT]
[PORT] for the port you want to run it on, or leave it empty to run it on port 25, the default for SMTP.
Next make sure that your development setup is configured to use Dumbster as its SMTP server and you are good to go.
Once you have run your tests, or done what you need to do, you can have a look at what Dumbster has collected. They easiest way is to telnet into it. Once you have connected you need to be polite and say
HELO. You’re then free to inspect your email.
To see how many emails Dumbster has collected simply type
LIST into the terminal. You should see something like this.
$ telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 localhost Dumbster SMTP service ready HELO 250 OK LIST 250 There are 2 message(s).
To see an individual message you need to specify the index of the message, with the numbering starting at 0. You should see something like this.
LIST 0 250 ------------------------------------------- Subject: This is a subject Date: Tue, 14 Feb 2012 09:10:57 +0000 To: email@example.com From: blog@ghosty This is an interesting test message. There are 2 message(s).
Once you are done, type the
QUIT command so that you free the server up to run more tests. The server will only allow a single connection at a time, and so if you leave your connection open, other applications will hang on the connection.
Well it turns out that I was wrong. The ability to do this stuff exists, I was just unaware of it, and because of my willingness to accept the status quo, I never bothered to look for a way.
The missing piece of the puzzle is actually something that I have been using for a while. Xdebug. I have been using it to generate grind files, which allow you to profile your script using tools like WebGrind.
Add the following in your php.ini.
xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000
Then, in NetBeans, go to your options window and select the PHP tab. Make sure that the Debugger Port corresponds to the one that you have set in your ini file.
Finally, restart your web server and have fun using breakpoints.
There is also a really useful guide from NetBeans on how to debug PHP using the inbuilt tools available to you.
Recently I have started to play with making my own themes for WordPress. Rather than start from the ground and reinvent the wheel, I decided to use a base theme which I can then extend. I also opted to use the brilliant Compass css framework to speed up development. Im going to talk about how I set my project up to get the most out of these tools.
Recently I have started deploying more and more versions of the WordPress code base for different projects that I have been working on, and a couple of them have been network (multisite) installs. For those who dont know what a multisite install is, well it allows you to run several instances of wordpress off a single codebase.
There are two ways [out of the box] that a network can run:
- Sub directories
- Sub domains
But all is not lost
If you log into the excellent Dreamhost panel to administer your account then you can set up your domains, you can follow these steps to get the new site hosted.
- Log into Dreamhosts Panel
- Click Manage Domains
- Click Add New Domain
- Scroll down and fill out the Mirror Domain form. Enter the new wordpress site into the “Create the mirror at” field, and choose the main wordpress network address from the dropdown for the mirror this site field. Finally click mirror this domain.
- You should see the success notification.
Sit back and relax
Thats not all folks
If you also take the time to install the WordPress Domain Mapping plugin, then you can use the process above to host completely different domains off of a single wordpress codebase. How cool is that.