Creating Orders with Custom Line Items using the Drupal Commerce API

If you've found yourself needing to create a custom order with the Commerce API, you've likely come across this article "Creating orders with the Drupal Commerce API" or found your answer from the Commerce Examples module. The solution provided works great, but it doesn't tell you how to assign values to custom fields you've created for line items. Here's how you do it.

Solution to "Notice: Undefined index: access in _menu_translate()"

The error "Notice: Undefined index: access in _menu_translate()..." shows when Drupal is looking for a access callback that doesn't exist (see _menu_check_access() does not warn when the access callback does not exist).
I came across this error when working with the Entity API and using Model as my base. I had to change the module and entity names, but I forgot one. So the access callback in hook_menu() was looking for the wrong function. But instead of telling me that, Drupal threw that "Undefined index" error.

Display Blocks Based on Node Taxonomy in Drupal without Coding

I needed to display a block based on a few conditions: Display on the node page for a particular content type. Only show up if that node had a particular taxonomy term assigned. Drupal let's you control the visibility settings for blocks, but the options are limited to Pages, Content types, Roles, and Users. Content types would allow me to let the block appear for my content type, but not based on it's taxonomy terms.

A Summary of Overriding template files in Drupal 7

Drupal's theme system allows you to provide alternate template files by way of theme hook suggestions. In other words, you can override the output of nodes, pages, blocks, and more by providing your own template file and using the correct naming scheme. For more information on that naming scheme I suggest reading this article on Drupal 7 Theme Hook Suggestions.

Preprocessing Fields from a Module in Drupal 7

If you're looking to preprocess a field in Drupal 7, you can use hook_preprocess_HOOK. The first "hook" is the name of your module. The second "HOOK" is the theme hook you want to preprocess (e.g. theme_node, theme_block, theme_link, theme_field). You can fine an exhustive list of the Drupal theme hooks by searching the Drupal API.

Here is a simple example of how to use it with fields.

Print Variables to Screen in Drupal

One of the most useful things I discovered in Drupal was how to print variables to the screen. I use it in almost every project I work on, so I thought I'd share this little snippet. All you have to do is print your variable using Drupal's the drupal_set_message function to send it to the screen. And by wrapping it in a sprint_f, print_r, and pre tag we can safely output it in a nice format.

Subscribe to RSS - drupal