You are here

function iframe_content_migrate_instance_alter in Iframe 7

Implements hook_content_migrate_instance_alter().

Use this to tweak the conversion of instance or widget settings from the D6 style to the D7 style for specific situations not handled by basic conversion, as when formatter or widget names or settings are changed.

File

./iframe.content_migrate.iframe.inc, line 46
iframe.content_migrate.iframe.inc Code to implement Content Migrate hooks on behalf of the Iframe module.

Code

function iframe_content_migrate_instance_alter(&$instance_value, $field_value) {

  // Translate formatters.
  if ($instance_value['widget']['type'] == 'iframe') {

    #iframe_debug(0, 'iframe_content_migrate_instance_alter', array($instance_value, $field_value));
    foreach ($instance_value['display'] as $context => $settings) {
      switch ($settings['type']) {
        case 'asurl':
          $instance_value['display'][$context]['type'] = 'iframe_formatter_asurl';
          break;
        case 'asurlwithuri':
        case 'asurl_withuri':
          $instance_value['display'][$context]['type'] = 'iframe_formatter_asurlwithuri';
          break;
        case 'iframeonly':
        case 'only':
          $instance_value['display'][$context]['type'] = 'iframe_formatter_only';
          break;
        case 'default':
          $instance_value['display'][$context]['type'] = 'iframe_formatter_default';
          break;
        case 'hidden':
          $instance_value['display'][$context]['type'] = 'iframe_formatter_hidden';
          $instance_value['display'][$context]['label'] = 'hidden';
          break;
        default:

          // Handle formatters using imagecache. D7 does not store them in the same way.
          $instance_value['display'][$context]['type'] = 'iframe_formatter_only';
      }
    }

    // Translate the original widgets.
    $instance_value['widget']['type'] = 'iframe_widget_urlwidthheight';
    if (isset($instance_value['default_value'][0]) && is_array($instance_value['default_value'][0]['attributes'])) {

      // settings are now a instance settings.
      $settings =& $instance_value['default_value'][0];
      foreach (array(
        'class',
        'width',
        'height',
        'frameborder',
        'scrolling',
        'transparency',
        'tokensupport',
      ) as $attr) {
        if (isset($settings['attributes'][$attr])) {
          $field_value['settings'][$attr] = $settings['attributes'][$attr];
          $default_attributes[$attr] = $settings['attributes'][$attr];
        }
      }
      unset($instance_value['default_value'][0]['attributes']);
    }
  }
}