You are here

function ds_update_4 in Display Suite 6.3

Same name and namespace in other branches
  1. 6.2 ds.install \ds_update_4()

Implementation of hook_update_N().

File

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

Code

function ds_update_4() {
  $ret = array();

  // Create schema.
  $schema = ds_schema();
  foreach ($schema as $name => $spec) {
    db_create_table($ret, $name, $spec);
  }

  // Refresh static cache.
  drupal_get_schema('ds_settings', TRUE);
  $all_build_modes = ds_get_build_modes(NULL, TRUE);

  // Take the 'module'_display_settings and store them in the table.
  foreach (module_implements('ds_api') as $module) {
    $api_info = ds_api_info($module);
    $module = $api_info['module'];
    $title = $api_info['title'];

    // Get all types.
    foreach ($api_info['types']() as $tkey => $type) {

      // Get the display settings.
      $settings = array();
      $display_settings = variable_get($module . '_display_settings_' . $type->type, array());
      if (!empty($display_settings)) {

        // Iterate over known build modes and save them.
        $build_modes = $all_build_modes[$module];
        foreach ($build_modes as $build_mode => $value) {
          if (isset($display_settings[$build_mode])) {
            $settings = $display_settings[$build_mode];

            // Iterate over fields and ditch those which are hidden.
            foreach ($settings['fields'] as $field_key => $field_value) {
              if ($field_value['region'] == 'disabled') {
                unset($settings['fields'][$field_key]);
              }
            }

            // Save the record.
            $record = new stdClass();
            $record->module = $module;
            $record->type = $type->type;
            $record->build_mode = $build_mode;
            $record->settings = serialize($settings);
            drupal_write_record('ds_settings', $record);
          }
        }
      }

      // Delete variable.
      variable_del($module . '_display_settings_' . $type->type);
    }

    // Remove the fields cached.
    variable_del('ds_fields_cached');
  }
  return $ret;
}