Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to define a new input format programmatically, probably as part of my module's hook_install(). I need to write code that duplicates the manual operations described on http://drupal.org/node/778976.

I have not been able to learn how to do this. Any pointers in the right direction will be appreciated.

share|improve this question
This edit has made the question more clear. Taking back my answer, because it's obviously not applicable here ;-) – AjitS Dec 15 '12 at 18:46
up vote 3 down vote accepted

Code from standard Drupal profile is your friend: http://drupalcode.org/project/drupal.git/blob/c5d6e6334fb7a71ecf1dbc7e06a7de8ad9547b27:/profiles/standard/standard.install#l14

  // Add text formats.
  $filtered_html_format = array(
    'format' => 'filtered_html',
    'name' => 'Filtered HTML',
    'weight' => 0,
    'filters' => array(
      // URL filter.
      'filter_url' => array(
        'weight' => 0,
        'status' => 1,
      // HTML filter.
      'filter_html' => array(
        'weight' => 1,
        'status' => 1,
      // Line break filter.
      'filter_autop' => array(
        'weight' => 2,
        'status' => 1,
      // HTML corrector filter.
      'filter_htmlcorrector' => array(
        'weight' => 10,
        'status' => 1,
  $filtered_html_format = (object) $filtered_html_format;

Enable permission for system roles (code):

// Enable default permissions for system roles.
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array($filtered_html_permission));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($filtered_html_permission));
user_role_grant_permissions(variable_get('user_admin_role', 0), array($filtered_html_permission));
share|improve this answer
@GisleHannemyr answer was updated. – kalabro Dec 15 '12 at 18:50
@GisleHannemyr variable_get('user_admin_role', 0) – kalabro Dec 15 '12 at 20:12
Filter and input format are different things. Filter can be defined in your module with hook_filter_info and attached to any input format. – kalabro Dec 16 '12 at 7:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.