You are here

function ds_enable in Display Suite 7

Implements hook_enable().

File

./ds.install, line 28
Display suite install file.

Code

function ds_enable() {
  $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE format = :format', 0, 1, array(
    ':format' => 'ds_code',
  ))
    ->fetchField();

  // Add a Display Suite code text format, if it does not exist. Do this only for the
  // first install (or if the format has been manually deleted) as there is no
  // reliable method to identify the format in an uninstall hook or in
  // subsequent clean installs.
  if (!$format_exists) {
    $ds_format = array(
      'format' => 'ds_code',
      'name' => 'Display Suite code',
      // 'Plain text' format is installed with a weight of 10 by default. Use a
      // higher weight here to ensure that this format will not be the default
      // format for anyone.
      'weight' => 12,
      'filters' => array(
        // Enable the DS evaluator filter.
        'ds_code' => array(
          'weight' => 0,
          'status' => 1,
        ),
      ),
    );
    $ds_format = (object) $ds_format;
    filter_format_save($ds_format);
    drupal_set_message(t('A <a href="@ds-code">Display Suite code</a> text format has been created.', array(
      '@ds-code' => url('admin/config/content/formats/' . $ds_format->format),
    )));
  }
}