Tag Archives: Drupal

Make your Drupal 7 faster by removing all revisions

Maybe you were in the same case as me. I got a big database full of revision rows in every revision table with their usefulnessofmeter beyond zero. In fact, I’m pretty sure revisions are not needed in 99.999% Drupal installation.

So, I tried to remove them by disabling the create a revision default option in my content type settings but it didn’t change anything. When you check the database manually, you can see every field has it’s own revision table. If you install the field_collection module, every collections and their fields have a revision table too. I got millions of revisions in some tables for just a few nodes. It was hell. Read More →

Drupal 7 Optimizations, Make it faster in one single line !

I just discovered something today that should interest lots of people :P Did you know Drupal saves each notice and error in his report logs ? If you have a custom script that generates for example 1000 notices, Drupal does 1000 notice database inserts before you get results. The script execution will never fail and you won’t be warned of these. Read More →

How to create a user programmatically in Drupal ?

Why would you need to load or create a Drupal user from your PHP script ? Because you can associate processes and node importations with a user to identify them quickly into the Drupal content administration ! Then, it’s faster to create it programmatically if it doesn’t exist.

If you want to create or retrieve a Drupal user from your PHP Script, pretty simple: Read More →

How to use Drupal into a custom PHP Script ?

I had to make a Drupal data importation script in PHP to be processed every day. You have to follow a few steps to succeed.

First I had to remove PHP time out and memory limits to avoid failures. Drupal script can take a long time to execute, so many tables, queries, caches and joins every where… Read More →

How to deal with your custom module updates ?

At first, it can be hard to maintain and update your custom module but when you understand how it works, it’s pretty easy.

In your module.install file you will create a function for each update you want to make, for example, you forgot to add an agenda field in your content type : Read More →

How quickly send a mail with a Drupal module ?

You made a PHP script associated to a Drupal module and you want to be alerted of custom special events or big fails

In your module file, just implement the hook_mail() like this : Read More →

Create a node content type programmatically

If you’re a new Drupal user, you may have already created a fresh content type manually to organize your site correctly. But what happens if you want to create this content type with your module installation and don’t want to do it manually each type you install it on a new website ?. Here is how to create a content type programmatically with Drupal 7.  Read More →

Add taxonomy with custom fields programmatically

Taxonomies are very useful in Drupal when you need to organize your content but sometimes the default and available fields are not enough. Here is an example how you can add some to you taxonomy vocabulary.

If you want to create a taxonomy from a PHP script, here is what you could do: Read More →

How to change default properties on custom drupal type nodes ?

If you want to set some default properties on your freshly created custom node type on Drupal, you have to use variable_set syntax like this:

In your <my_custom_module_name>.install file, add these lines according to what you need to set.

If you want a language to be set by default, use this:

  • 0 – Disabled
  • 1 – Enabled
  • 2 – Enabled with translation (core’s translation.module – TRANSLATION_ENABLED)
  • 4 – Enabled, with field translation (entity_translation.module – ENTITY_TRANSLATION_ENABLED) Read More →