You are here

function fe_block_settings_features_revert in Features Extra 7

Same name and namespace in other branches
  1. 6 fe_block.module \fe_block_settings_features_revert()

Implements hook_features_revert().

2 calls to fe_block_settings_features_revert()
fe_block_settings_features_enable_feature in fe_block/fe_block.module
Implements hook_features_enable_feature().
fe_block_settings_features_rebuild in fe_block/fe_block.module
Implements hook_features_rebuild().

File

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

Code

function fe_block_settings_features_revert($module_name = NULL) {
  $component = 'fe_block_settings';
  $defaults = features_get_default($component, $module_name);
  if (empty($defaults)) {
    return;
  }

  // We remove the version, as we now want to deal with actual block settings.
  unset($defaults['version']);
  $themes_rehashed = array();
  $active_themes = _fe_block_get_active_themes();

  // The fallback theme for theme specific settings.
  $theme_default = variable_get('theme_default', 'bartik');
  foreach ($defaults as $block) {

    // Core custom blocks are prepared with a delta value.
    $block = _fe_block_prepare_custom_blocks_for_import($block);

    // Remove the additional settings from the block array, to process them
    // later. We explicitely set NULL, if no setting was given in the defaults.
    $block_themes = $block['themes'];
    $block_node_types = isset($block['node_types']) ? $block['node_types'] : NULL;
    $block_roles = isset($block['roles']) ? $block['roles'] : NULL;
    $block_css_class = isset($block['css_class']) ? $block['css_class'] : NULL;
    $block_i18n_block_language = isset($block['i18n_block_language']) ? $block['i18n_block_language'] : NULL;
    unset($block['themes']);
    unset($block['node_types']);
    unset($block['roles']);
    unset($block['css_class']);
    unset($block['i18n_block_language']);

    // Restore theme specific settings for every active theme.
    foreach ($active_themes as $theme) {

      // Rehash if we did not yet.
      if (empty($themes_rehashed[$theme])) {
        _block_rehash($theme);
        $themes_rehashed[$theme] = TRUE;
      }

      // Get the theme specific setting for the active theme.
      if (isset($block_themes[$theme])) {
        $key = $theme;
      }
      elseif (isset($block_themes[$theme_default])) {
        $key = $theme_default;
      }
      else {
        $key = key($block_themes);
      }

      // Write block settings.
      $write = array_merge($block, $block_themes[$key]);
      drupal_write_record('block', $write, array(
        'module',
        'delta',
        'theme',
      ));
    }

    // Ensure global settings.
    _fe_block_settings_update_global_settings($block);

    // Set node type settings
    // (only if there were some defined, to avoid overwriting not yet exported
    // data).
    if (isset($block_node_types)) {
      _fe_block_settings_update_block_node_type_settings($block, $block_node_types);
    }

    // Apply role visibility settings.
    if (isset($block_roles)) {
      _fe_block_settings_update_block_roles($block, $block_roles);
    }

    // Update block CSS classes.
    if (isset($block_css_class) && module_exists('block_class')) {
      _fe_block_settings_update_block_css_class($block, $block_css_class);
    }

    // Set i18n_block languages.
    if (module_exists('i18n_block') && isset($block_i18n_block_language)) {
      _fe_block_settings_update_i18n_block_language($block, $block_i18n_block_language);
    }

    // Apply blockcache_alter settings.
    if (module_exists('blockcache_alter')) {
      _fe_block_settings_update_block_cache_alter($block);
    }
  }

  // Clear block cache.
  cache_clear_all(NULL, 'cache_block');
  return TRUE;
}