You are here

function ds_import_data in Display Suite 6

Same name and namespace in other branches
  1. 6.3 includes/ds.tools.inc \ds_import_data()
  2. 6.2 includes/ds.tools.inc \ds_import_data()

Import data function.

Parameters

array $data A complete data array with settings.:

boolean $dsm Whether to output drupal messages.:

boolean $override Whether to override existing settings or not.:

string $revert_module The module to revert.:

string $revert_type The object type to revert.:

string $revert_build_mode The build mode to revert.:

2 calls to ds_import_data()
ds_import_default_data in ./ds.module
Import default display data from modules.
ds_import_submit in includes/ds.tools.inc
Import submit function.

File

includes/ds.tools.inc, line 64
Tools for Display suite like export & import.

Code

function ds_import_data($data, $dsm = TRUE, $override = TRUE, $revert_module = '', $revert_type = '', $revert_build_mode = '') {
  foreach ($data as $module => $value) {
    foreach ($value as $type => $settings) {
      if ($dsm) {
        drupal_set_message(t('Saved display settings for @module and @type', array(
          '@module' => $module,
          '@type' => $type,
        )));
      }
      $old_settings = variable_get($module . '_display_settings_' . $type, array());
      foreach ($settings as $build_mode => $setting) {

        // Override no matter what. This comes from the import settings screen.
        if ($override) {
          $settings[$build_mode]['status'] = DS_SETTINGS_UI;
        }
        else {
          if (isset($old_settings[$build_mode]['status']) && $old_settings[$build_mode]['status'] == DS_SETTINGS_OVERRIDDEN) {
            if ($module == $revert_module && $type == $revert_type && $build_mode == $revert_build_mode) {
              $settings[$build_mode]['status'] = DS_SETTINGS_DEFAULT;
            }
            else {
              $settings[$build_mode] = $old_settings[$build_mode];
            }
          }
          else {
            $settings[$build_mode]['status'] = DS_SETTINGS_DEFAULT;
          }
        }
      }

      // Keep old settings which aren't in the imported ones.
      if (!empty($old_settings)) {
        foreach ($old_settings as $build_mode => $setting) {
          if (!isset($settings[$build_mode])) {
            $settings[$build_mode] = $old_settings[$build_mode];
          }
        }
      }
      variable_set($module . '_display_settings_' . $type, $settings);
    }
  }
}