Time from time, while doing your custom Drupal code, you may want to load only one or several specific fields from a defined set of entities. So actually you have three approaches to this:

1. Query for entity/node set and load whole entities to get desired fields data. Works, but not a performant solution.

2. Make a direct sql query and get desired fields out of your database. Works too, is the fasted in terms of performance solution, but not too flexible and portable.

3. Leverage EntityFieldQuery() and field_attach_load(). This approach is not as fast as the second, but way more faster than loading whole nodes, it is flexible and uses field caching mechanism. If you'll decide to change your database backend later in the future, let's say to MongoDB, you'll be able to switch without changing a line in your code, neat!

I’ve been using menu position module (http://drupal.org/project/menu_position) for some time and this is a really handy module I must say. It lets you set an active menu item based on different conditions. For example: you want products menu item to be set as active while you’re browsing nodes of content type “Products”.

A week ago Packt Publishing approached and asked me to review their new book called “Drupal Rules How-To” written by Robert Varkonyi. I like getting books for a review, because it motivates you to read. With my working schedule it’s hard to find time for another tech read, but when you give a promise to someone, you can’t retreat ;) So I agreed, read the book and here is my unbiased review.

I’ve recently finished working on a project for a client. This was an interesting journey and I want to tell you about it.

Wanted to share with you all a cool thing I got for Christmas from my cool wife :) A handmade Druplicon!

Handmade Druplicon

I guess I'm spending too much time with Drupal if even my wife knows how Druplicon looks like ;)

I want to wish Merry Christmas to all Drupal people all over the world!


Get away of your computers, nodes, views and entities. Type exit in your terminal and spend some time with your family :) They deserved it.

Time from time you need to update single or several specific fields of your entity in Drupal. It can be node, comment, taxonomy or some other custom entity. So how do we usually do this? Let's see:

Ok, you're clever guy/girl and don't use some generic modules like computed field, right? And you want to change some node field data based on your conditions, right? What will you do? Of course, write your manipulation using hook_node_presave(), but there are some circumstances, when this hook won't work (for example, you need a node id for a "to be created" node, which isn't available in hook_node_presave()) and you will have to deal with hook_node_insert() and hook_node_update(), so what will you do then?

Drupal 7 (and, obviously Drupal 8) breathe by entity. Entities are everywhere and you can't code a site without them. But here is the problem: all entities have ids, but these ids have different names accross Drupal. Just to give you few examples: Entity id in Node is $node->nid, Entity id in User is $user->uid and so on. Inconsistency as you may say. What if you want to write a code which works accross all entities, how to get entity id for every entity type without writing additional code? I'll show you how.

A quick tip: If you don't want to have a "reply" link in your comments, here is a simple way to remove this link.


Subscribe to TimOnWeb RSS