Embed Fields of an Entity to a Form in Drupal 7

Entities are one of the most important concepts introduced in Drupal 7. It is clear now that, it got further expanded in Drupal 8.

Sometimes requirements may arise that want you to embed/add fields for an entity within a another form, possibly custom form you created in your module. With this article I am trying to show you how to achieve it. I will show it by embedding fields for a page node within a custom form. To keep things simple, the custom form do nothing other than just showing a text input field and allows to add/edit a page node. Continue Reading

Right Method to Get the Language Code for a Given Drupal 7 Entity

While programming for Drupal, it is a very common scenario to get the language code for a given entity. A bad practice being followed by many programmers is hard-coding the value 'und' directly as language code. Some programmers will take 'language' property of the entity object, this only works for entity of type node and entities that have property named ‘language’ as entity key for language. Continue Reading

Drupal 7 Get Default Files Directory Path

While working on Drupal coding, sometimes you may want to get the default files directory path. Here it is said as ‘default’ intentionally, as you can configure a Drupal installation to have default directory as public or private. For most of the sites it will public files directory.

Use following code snippet to get default files directory path.

drupal_realpath(file_default_scheme() . '://');

Or, if you want to get public or private files directory path specifically. Then you can use this to get public directory.


Or, for private directory path.


Moving Preprocess Functions to Separate Files in Drupal 6 & 7

When you implement hook_theme() in Drupal, there is provision to specify the file which should be loaded for the theme functions and preprocess functions to be found. So, we can simplify module file by moving out theme function and preprocess function of our theme entries to separate file. This also has added benefit of reducing module loading. On each bootstrapping Drupal will load every .module file those are of enabled modules. So we should consider moving out code from .module file and also giving modular structure. Continue Reading

Fixing gd Problem in PHP on Ubuntu 11.04

I was trying to enable gd for php in Ubuntu 11.04. As usual it should be typing in terminal:

sudo apt-get install php5-gd

Unfortunately it does not worked and gd was not enabled

Typing the command ‘php -a’ I was getting:

“PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20090626+lfs/gd.so’ – /usr/lib/php5/20090626+lfs/gd.so: undefined symbol: gdImageCreateFromJpeg in Unknown on line 0″ Continue Reading

Resource Loader for PHP Web Applications

I wrote a resource loader class for PHP web applications. The class will help to manage loading of JavaScripts and CSSs we include within our web pages. Usually these JavaScripts and CSSs have dependencies with other scripts and or CSSs. For example, we have to load jQuery script file before any script that utilise jQuery functionalities within the code. And we have to ensure that we are including the scripts in the correct order. By using this Resource loader class we can forget about it.

Once initialised, we can register script and/or CSS style links or raw scripts and/or CSS styles with resource loader object. Then finally we can render everything in correct order in our web page to deliver to client side browser. Continue Reading

KeyMagic with Malayalam

Until now Malayalam community were using a customised free version of old Keyman to type anywhere in a Windows system. Me too was using it in all places except Malayalam Wikimedia projects, on Malayalam Wikimedia projects I use our Narayam which is a built in Malayalam typing solution integrated to Wikis. People were always complaining about Keyman that is does not work on Windows Vista and 7 systems. And even I had started to develop a solution to replace Keyman based solution, I stopped further developments soon after I fully changed my platform to Ubuntu. Continue Reading

Oriya Supported

Added support for Oriya to Narayam extension. Currently added schemes for Oriya are transliteration and InScript. Subhashish Panigrahi helped to fix the issues in transliteration scheme. I think more issues may come later, as they want more tuning on it. Oriya translator at translatewiki can use this schemes to help their contributions.

Since its creation to just before Oriya Wikipedia was less active. Shiju Alex is helping to build a community there. After Oriya typing feature active, I hope, more Oriya people will show their interest in the project, as the one  major barrier has bee solved.

Sinhala In Narayam

Yesterday (2011/03/01) I added two Sinhalese schemes, Singlish and Wijesekara, to Narayam. Now there available at translatewiki. Thus Sinhalese people can contribute more translations without depending on third party tools.

There are minor issues in Singlish scheme implementation since it is a phonetic one. Hope those issues can be fixed soon.