You are here

ds.install in Display Suite 7

Display suite install file.

File

ds.install
View source
<?php

/**
 * @file
 * Display suite install file.
 */

/**
 * Implements hook_install().
 */
function ds_install() {
  db_update('system')
    ->fields(array(
    'weight' => 1,
  ))
    ->condition('name', 'ds')
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function ds_uninstall() {
  variable_del('ds_styles_regions');
}

/**
 * Implements hook_enable().
 */
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),
    )));
  }
}

/**
 * Implements hook_disable().
 */
function ds_disable() {
  drupal_set_message(t('The Display Suite module has been disabled. Any existing content that was using the Display Suite filter will now be visible in plain text. This might pose a security risk by exposing sensitive information, if any, used in the PHP code.'));
}

/**
 * Implements hook_schema().
 */
function ds_schema() {
  $schema['ds_field_settings'] = array(
    'description' => 'The table that holds display suite field settings per display.',
    // CTools export definitions.
    'export' => array(
      'key' => 'id',
      'identifier' => 'ds_fieldsetting',
      'default hook' => 'ds_field_settings_info',
      'can disable' => FALSE,
      'api' => array(
        'owner' => 'ds',
        'api' => 'ds',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'id' => array(
        'description' => 'The unique id this setting.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_type' => array(
        'description' => 'The name of the entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'bundle' => array(
        'description' => 'The name of the entity.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'view_mode' => array(
        'description' => 'The name of the view_mode.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'description' => 'The display suite field settings for this layout.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'ds_entity' => array(
        'entity_type',
      ),
      'ds_bundle' => array(
        'bundle',
      ),
      'ds_view_mode' => array(
        'view_mode',
      ),
    ),
  );
  $schema['ds_layout_settings'] = array(
    'description' => 'The table that holds the layouts configuration.',
    // CTools export definitions.
    'export' => array(
      'key' => 'id',
      'identifier' => 'ds_layout',
      'default hook' => 'ds_layout_settings_info',
      'can disable' => FALSE,
      'api' => array(
        'owner' => 'ds',
        'api' => 'ds',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'id' => array(
        'description' => 'The unique id the layout.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_type' => array(
        'description' => 'The name of the entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'bundle' => array(
        'description' => 'The name of the entity.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'view_mode' => array(
        'description' => 'The name of the view_mode.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'layout' => array(
        'description' => 'The name of the layout.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'description' => 'The settings for this layout.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'ds_entity' => array(
        'entity_type',
      ),
      'ds_bundle' => array(
        'bundle',
      ),
      'ds_view_mode' => array(
        'view_mode',
      ),
    ),
  );
  $schema['ds_view_modes'] = array(
    'description' => 'The table that holds custom view modes managed by Display Suite.',
    // CTools export definitions.
    'export' => array(
      'key' => 'view_mode',
      'identifier' => 'ds_view_mode',
      'default hook' => 'ds_view_modes_info',
      'can disable' => FALSE,
      'api' => array(
        'owner' => 'ds',
        'api' => 'ds',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'view_mode' => array(
        'description' => 'The machine name of the view mode.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'label' => array(
        'description' => 'The label of the view mode.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'entities' => array(
        'description' => 'The entities for this view mode.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'view_mode',
    ),
  );
  $schema['ds_fields'] = array(
    'description' => 'The table that holds custom fields managed by Display Suite.',
    // CTools export definitions.
    'export' => array(
      'key' => 'field',
      'identifier' => 'ds_field',
      'default hook' => 'ds_custom_fields_info',
      'can disable' => FALSE,
      'api' => array(
        'owner' => 'ds',
        'api' => 'ds',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'field' => array(
        'description' => 'The machine name of the field.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'label' => array(
        'description' => 'The label of the field.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'field_type' => array(
        'description' => 'The type of of the field',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
      'entities' => array(
        'description' => 'The entities for this field.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
      'properties' => array(
        'description' => 'The properties for this field.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'field',
    ),
  );
  return $schema;
}

/**
 * Update the weight of Display Suite.
 */
function ds_update_7001() {
  db_update('system')
    ->fields(array(
    'weight' => 1,
  ))
    ->condition('name', 'ds')
    ->execute();
}

/**
 * Updates the ds_layout_settings table.
 */
function ds_update_7002() {
  $schema = ds_schema();
  db_change_field('ds_layout_settings', 'layout', 'layout', $schema['ds_layout_settings']['fields']['layout']);
}

/**
 * Trigger an update to clear the cache.
 */
function ds_update_7003() {
}

/**
 * Updates the ds_layout_settings table.
 */
function ds_update_7004() {
  $schema = ds_schema();
  db_change_field('ds_layout_settings', 'bundle', 'bundle', $schema['ds_layout_settings']['fields']['bundle']);
  db_change_field('ds_field_settings', 'bundle', 'bundle', $schema['ds_field_settings']['fields']['bundle']);
}

Functions

Namesort descending Description
ds_disable Implements hook_disable().
ds_enable Implements hook_enable().
ds_install Implements hook_install().
ds_schema Implements hook_schema().
ds_uninstall Implements hook_uninstall().
ds_update_7001 Update the weight of Display Suite.
ds_update_7002 Updates the ds_layout_settings table.
ds_update_7003 Trigger an update to clear the cache.
ds_update_7004 Updates the ds_layout_settings table.