Backend · Drupal · Drupal 6 & Drupal 7 · Frontend · How To · PHP · Solution to Error

Drupal Role Specific Development Feedback

On rare occasions you may have to work on a production site and need some development feedback.
If you want to control which role sees your output, this snippet can help.

With this logic in place, only appropriate roles will see your working on the site.

Backend · Drupal · Drupal 6 & Drupal 7 · Frontend · PHP · Solution to Error

Drupal Display PHP Errors on One Domain of Multi Site

When using a multi-site setup, You may want errors only to appear for one site. In that case, use $_SERVER[‘HTTP_HOST’] in an if statement to only display PHP error messages for the domain of your choice:

Backend · Drupal · File System Related · How To · PHP

Simple REST Client in PHP

A while back I created a Drupal module to act as a customized and extensible REST client. Since then I have used the module as a basis for other customized REST client code. I thought it might be a good idea to keep a copy of the dumbed down very basic code (not the Drupal module) in this post as a reference for myself and others to build off of in the future.

Any improvements or suggestions are welcome. However, please keep in mind that this is intended to be a scaffold on which to build customizations.

Backend · Drupal · Drupal 6 & Drupal 7 · File System Related · How To · PHP

How to Understand PHP Stream Wrapper Context and Options

Some have a difficult time understanding what is meant in PHP by stream wrappers, context options and parameters. Judging by a few conversations with other developers, its obvious there is a bit of confusion about what a stream wrapper is and why it would have a context. While the PHP documentation does adequately describe what this is, some just don’t “get it” the way that is described.

So if the descriptions of PHP Streams and Wrappers and contexts just make no sense when you read them, the following illustration is meant for you.

OK, picture yourself as a person in an assembly line. Whatever is coming down the line you need to be able to “handle it” and pass it along. Thing is, there are several possibilities of what might be coming down the line. It might be a hot casserole in metal pan. It might be a block of ice. It might be candy that needs to be wrapped. It might be glowing hot metal from a furnace. It might be liquid being poured from bucket to bucket. Can you see it in your minds eye?

OK, so if its liquid being poured from bucket to bucket, then you need a bucket, right? If it is a glowing hot piece of metal you better have your tongs handy! If it is a casserole fresh out of the oven then you need to have your stove mits on. If you being handed of a block of ice, then your large ice tongs will allow you to grasp it and pass it along.

The point is, to properly handle whatever is coming down the line (streamed data), you will need the appropriate tool(s) to handle the different kinds of items being passed (data types). The tools for handling each different kind of data type are the “parameters”. The parameters are like the tongs for the hot metal, the oven mits for the casserole or the foil in hand.

But how do you know which way of handling what is coming down the pipe? Simple, that is based on what the situation is. You know which type of item it is (which data type).

con·text (see link definition #2) synonyms: circumstances, conditions, factors

The “context” is determined by what exactly is being streamed. So for a different “contexts” (kinds of items) being “streamed” (passed along) the “parameters” (required tools for handling) the “data type” (kind of item) will change.

So for different data types being streamed the parameters will change. The term context simply makes reference to the fact that for different data types the situation is unique with its own required parameters. So now it hopefully makes sense to you that the PHP stream wrapper would require a context in order to know which parameters are needed to handle the data type.

The term “stream” makes reference to something being passed in or out of the application (on the assembly line).

The stream wrapper is code and relates to the person on the assembly line who is responsible for passing the stream along. It “decides” how to handle what is being passed.

The context is determined by WHAT is being passed along.
Based on the context, the option and parameters will change to properly handle what data type is being handled.

With that in mind, the concept is really quite simple. HTTP has options and parameters that are different from cURL options and parameters. PHP stream wrapper FTP options that differ from say SSL context options and so on.

Hopefully, with this understanding to help grasp what’s happening with PHP stream wrappers and contexts, reading the PHP stream wrapper documentation will make a lot more sense.

Drupal · Drupal 6 & Drupal 7 · Drush · Linux

Drush Specific Database Comands with Drush Aliases

I was looking for a way to clear cache on specific sites as I have a a Drupal Multi-Site setup that has more than one database. Sometimes I only want to clear cache on one database at a time.

Since it took longer than 5 minutes : ) to find advice on this subject, I am posting here in hopes that it will help.

There is a little up-front set up involved but it is worth it when you have a setup with multiple databases.

Drush aliases are a powerful tool to get to know. With Drush aliases, it is possible to run commands on a remote server from your local server. Pretty awesome if you like to save time.

Here is an example for setting up drush aliases:

Drupal · Drupal 6 & Drupal 7 · Git · How To

Git, How to Cherry Pick

When maintaining a team of developers and keeping track of all the code changes it is important to be able to select pieces of functionality that you can include and exclude at will.

This will allow one to manage the progress of a project better.

At times you may need to go back in the history of the repository and select a single commit or two and re-commit them in your current branch.

Git makes this pretty easy with git cherry-pick

Here is one way to do it:

CSS · Drupal · Drupal 6 & Drupal 7 · Drush · Web Design

drush cc Not Showing All Options (only showing 2 options cancel and drush)

Trying to clear your Drupal site chache with drusch cc or drush cc all?
Drush should out put a list in response that looks like this:

But instead, you may see something that looks like this:

Chances are you are not in the document root of the Drupal site on which you are trying to clear the cache.

Drupal · Drupal 6 & Drupal 7 · Linux · MAMP · Web Design

Drupal: How to solve Warning: file_put_contents The file could not be created

Sometimes when migrating or setting up a local development site you may run into an error that looks like this:

Likely the Drupal temp directory isn’t writable.

An easy fix for this is to navigate to /admin/config/media/file-system
and enter the correct temporary directory or if you’re not sure what it should be, then delete the one that is entered in the field under the label “Temporary directory”. Drupal is able to detect it.

I hope this helps someone!

Drupal · Drupal 6 & Drupal 7 · Frontend · How To · Web Design

Drupal 7: How To Create a Views View from Within a Module (default view)

The whole idea in making a module is to make it, well ‘modular’, right? The person who is going to install the module should not have to create and configure a view. Chances are they would not get it just right anyway (you know, with all the exact settings the module depends upon). This is because the Views UI is so versatile that no two people are likely to set it up the exact same way. In many cases, if a module depends on data from a view, all the Views setting need to be just so in order for the module to work its magic.

Although this is very doable, I found it very difficult to locate documentation spelling out just how to do it. I’m not sure if it was not documented in a way that was easy to find or if it was the fact that I had a 3-day headache pounding away. Either way, I did finally come across a few links.

Drupal API

To give myself and others one more place to stumble upon what to do I have documented how to create a Views default view from within a module below. A default Views view is a view that weather enabled or not shows up on the /admin/structure/views page once a module is installed and enabled.

For the purpose of these notes we will call our module, ‘mymodule’. Everywhere you see ‘mymodule’ you need to replace with the name of your actual module name. This article assumes that you are familiar with module development basics and that you have already created your basic module files ( mymodule/mymodule.module, mymodule/mymodule.install & mymodule/ ).

OK, let’s create a default view in a module!

Create a new file named and save it into a directory named mymodule/includes/.

Inside the file you just created, paste the following function…

You can now create a View in the Views UI as you normally would.
Then export the view. Select the entire export text as presented in the textarea of the export result and past it in place of where you see “PASTE EXPORTED VIEW CODE HERE” inside the function you just made and save the file.

OK, next, inside the file your mymodule.module file, paste the following function (remember that everywhere you see ‘mymodule’ you need to replace with the name of your actual module name.).

Now you can clear your cache and see the default View you just created in the list of default views at ‘admin/structure/views’

Please feel free to register and comment.