How to get text formats allowed for the user - Drupal 7

Wed, 05/09/2012 - 15:21 | 13 Views

Hello folks,

If you are new in Drupal 7 and you need to deal with text formats (format input filters in D6), you will notice a big difference between D6 & D7. We don't have the radio button to set our default text format.

If you are wondering how we can set this default format, the answer lies in the order since Drupal 7 handles the text format with less weight as the default format.

As a reminder, it all depends on the roles assigned to the current user, the default order could be different depending on the role.

In case you need to get this somewhere in the code, you can use the following snippet (devel module required)

uid = 1;

$formats = filter_formats($user);
//Get all text formats enabled to user:1

//Get the default format for user:1
$default_format  = array_shift($formats);


Enjoy IT