You are here

function _fe_block_settings_convert in Features Extra 7

Helper function to convert an older export into the new format.

Parameters

array $defaults: array of fe_block_settings definition.

Return value

array array of current fe_block_settings definition

1 call to _fe_block_settings_convert()
fe_block_default_fe_block_settings_alter in fe_block/fe_block.module
Implements hook_default_fe_block_settings_alter().

File

fe_block/fe_block.module, line 1224
Provide features components for exporting core blocks and settings.

Code

function _fe_block_settings_convert($defaults) {
  $version = isset($defaults['version']) ? $defaults['version'] : 0;

  // Directly return if the version is the current one.
  if ($version == FE_BLOCK_VERSION) {
    return $defaults;
  }
  elseif ($version == '1.0') {

    // We try to get the default theme for the global definitions, else we take
    // the first.
    $theme_default = variable_get('theme_default', 'bartik');
    if (!isset($defaults['theme'][$theme_default])) {
      $theme_default = key($defaults['theme']);
    }
    $blocks = array();

    // We get the basic blocks from the visibility array.
    foreach ($defaults['visibility'] as $block_id => $base) {
      $node_types = array();
      if (isset($base['node_type'])) {

        // Node types were specified in node_type => TRUE/FALSE. Now we simply
        // list the selected node types.
        $node_types = array_keys(array_filter($base));
        unset($base['node_type']);
      }
      $block = $base;
      $block['node_types'] = $node_types;

      // Global settings.
      $globals = _fe_block_get_global_settings($defaults['theme'][$theme_default][$block_id]);
      $block = array_merge($globals, $block);

      // Build theme specific array.
      $block['themes'] = array();
      foreach ($defaults['theme'] as $theme => $items) {
        $block['themes'][$theme] = _fe_block_get_theme_specific_settings($items[$block_id]);
      }
      $blocks[$block_id] = $block;
    }

    // Set current version so we can compare it with current version defaults.
    $blocks['version'] = FE_BLOCK_VERSION;
    return $blocks;
  }
  elseif ($version == 0) {

    // We try to get the default theme for the global definitions, else we take
    // the first.
    $theme_default = variable_get('theme_default', 'bartik');
    if (!isset($defaults[$theme_default])) {
      $theme_default = key($defaults);
    }
    $blocks = array();
    foreach ($defaults as $theme => $items) {
      foreach ($items as $block_id => $item) {

        // Avoid php notices.
        if (!isset($blocks[$block_id])) {
          $blocks[$block_id] = array(
            'themes' => array(),
          );
        }

        // Set theme specific settings.
        $blocks[$block_id]['themes'][$theme] = _fe_block_get_theme_specific_settings($item);

        // We add the global settings for the default theme.
        if ($theme == $theme_default) {
          $globals = _fe_block_get_global_settings($item);
          $blocks[$block_id] = array_merge($blocks[$block_id], $globals);
        }
      }
    }

    // Set current version so we can compare it with current version defaults.
    $blocks['version'] = FE_BLOCK_VERSION;
    return $blocks;
  }
}