diff --git a/fe_block.module b/fe_block.module index 0354b5b..34424a3 100644 --- a/fe_block.module +++ b/fe_block.module @@ -91,23 +91,19 @@ function fe_block_settings_features_export($data, &$export, $module_name = '') { * Implements hook_features_export_render(). */ function fe_block_settings_features_export_render($module_name = '', $data) { - - $component = 'fe_block_settings'; - $default_hook = 'default_' . $component; - $theme_default = variable_get('theme_default', 'bartik'); - $code = array(); $code[] = ' $export = array();'; $code[] = ''; // Provide backwards compatibility. - // We can add "version" as block ids got at least a '-' within the string. + // We can use "version" here. Block ids always have a '-' in their string. $code[] = ' $export[\'version\'] = \'' . FE_BLOCK_VERSION . '\';'; $code[] = ''; // We get the default theme's block settings as master, and process theme // specific parts later in the loop. // The block settings are keyed by the FE block id. + $theme_default = variable_get('theme_default', 'bartik'); $blocks = _fe_block_info_by_theme($theme_default); // Active themes to cycle through. @@ -121,16 +117,16 @@ function fe_block_settings_features_export_render($module_name = '', $data) { // We start to build the export object for this block. // First we retrieve data that is valid for any theme. - $export_block = _fe_block_get_global_vars_from_block($block); + $export_block = _fe_block_get_global_settings($block); // Ensure core custom block export keys are transformed. $export_block = _fe_block_prepare_custom_blocks_for_export($export_block); // Add node type settings. $export_block['node_types'] = _fe_block_get_block_node_types($block); - // @TODO: role visibility settings. + // @todo: Add role visibility settings. // Add theme specific settings for every active theme. $export_block['themes'] = array(); foreach ($active_themes as $theme) { - $export_block['themes'][$theme] = _fe_block_get_theme_specifics_from_block($block); + $export_block['themes'][$theme] = _fe_block_get_theme_specific_settings($block); } // Sort export array keys. @@ -146,57 +142,55 @@ function fe_block_settings_features_export_render($module_name = '', $data) { $code[] = ' return $export;'; $code = implode("\n", $code); - return array($default_hook => $code); + return array('default_fe_block_settings' => $code); } /** - * Returns the drupal block defintion for a specific theme. + * Returns the block definitions for a specific theme. * * @param string $theme - * machine name of the theme + * Machine name of the theme. * * @return array - * array of block informations + * Array of block definitions. */ function _fe_block_info_by_theme($theme) { - // Backup theme settings, so theme is only switched in scope of this function. global $custom_theme, $theme_key; drupal_theme_initialize(); $backup = array($custom_theme, $theme_key); $return = array(); - $info = _block_rehash($theme); - foreach ($info as $block) { - $id = _fe_block_build_id($block); + $blocks = _block_rehash($theme); + foreach ($blocks as $block) { // Blocks are only valid for export if we got a fe_block id for them. - if ($id) { + if ($id = _fe_block_build_id($block)) { $return[$id] = $block; } } // Sort blocks by keys to get a consistent order. ksort($return); - // Restore the backuped theme keys. + // Restore the backed up theme keys. list($custom_theme, $theme_key) = $backup; return $return; } /** - * Retrieve the global part of the block definition. + * Retrieve the global (non-theme-specific) part of a block definition. * * @param array $block - * a single block's definition + * A block definition. * * @return array - * a filtered block definition, on none-theme-specific settings + * The block definition filtered on non-theme-specific settings. */ -function _fe_block_get_global_vars_from_block($block) { - $theme_spec_defaults = _fe_block_theme_specific_defaults(); +function _fe_block_get_global_settings($block) { + $theme_specific_defaults = _fe_block_theme_specific_defaults(); // Filter on any keys other than the theme specific ones. - $return = array_diff_key($block, $theme_spec_defaults); + $return = array_diff_key($block, $theme_specific_defaults); - // Removed the serial. + // Remove the serial. if (isset($return['bid'])) { unset($return['bid']); } @@ -211,32 +205,28 @@ function _fe_block_get_global_vars_from_block($block) { /** * Helper to prepare a core custom block for export. * - * The callback replaces the delta entry with the machine_name generated by - * fe_block, if the block is defined by core block module. + * Replaces the block delta that is used by the core block module with a unique + * machine name. * * @param array $block - * Block definition - can be only part of the original definition + * Block definition - can be only part of the original definition. * * @return array * Altered block array. */ function _fe_block_prepare_custom_blocks_for_export($block) { - $return = $block; - - // Core's custom blocks do not hold a delta but a machine_name, so we can - // handle them in our own import/export code. - if ($return['module'] == 'block') { - $return['machine_name'] = fe_block_get_machine_name($block['delta']); - unset($return['delta']); + if ($block['module'] == 'block') { + $block['machine_name'] = fe_block_get_machine_name($block['delta']); + unset($block['delta']); } - return $return; + return $block; } /** - * Helper to convert exported core custom block for import. + * Helper function. Prepares an exported core custom block for import. * * @param array $block - * Block definition form the import code. + * Block definition from the import code. * * @return array * Altered array with machine_name replaced by delta. @@ -253,12 +243,12 @@ function _fe_block_prepare_custom_blocks_for_import($block) { * Helper function to get the global settings for a block. * * @param array $block - * a single block's definition + * A single block definition. * * @return array - * a filtered block definition with only theme-specific settings + * A filtered block definition with only theme-specific settings. */ -function _fe_block_get_theme_specifics_from_block($block) { +function _fe_block_get_theme_specific_settings($block) { $defaults = _fe_block_theme_specific_defaults(); $return = array_intersect_key($block, $defaults); // Region. @@ -270,12 +260,13 @@ function _fe_block_get_theme_specifics_from_block($block) { } /** - * Helper to get theme specific default array. + * Helper function for filtering theme specific settings. * - * This is used to filter on the block array. + * @see _fe_block_get_global_settings() + * @see _fe_block_get_theme_specific_settings() * * @return array - * array of block columns and their default values. + * An array of default settings, keyed by name. */ function _fe_block_theme_specific_defaults() { return array( @@ -286,15 +277,14 @@ function _fe_block_theme_specific_defaults() { ); } - /** * Get node type visibility settings for the specified block. * * @param array $block - * block definition array + * Block definition array. * * @return array - * array of node types associated to the block + * Array of node types associated with the block. */ function _fe_block_get_block_node_types($block) { $query = db_select('block_node_type', 'bnt') @@ -313,7 +303,7 @@ function _fe_block_active_themes() { $theme_keys = array(); foreach ($themes as $key => $theme) { - // Add the theme keys to an array, for latter processing. + // Add the theme keys to an array, for later processing. // Default theme will be put in front. if (!empty($theme->status)) { $theme_keys[] = $key; @@ -366,7 +356,7 @@ function fe_block_settings_features_revert($module_name = NULL) { if (isset($block_themes[$theme])) { $key = $theme; } - // Or fallback on the defaut theme. + // Or fallback on the default theme. elseif (isset($block_themes[$theme_default])) { $key = $theme_default; } @@ -403,7 +393,7 @@ function fe_block_settings_features_revert($module_name = NULL) { * block definition */ function _fe_block_settings_update_global_settings($block) { - $globals = _fe_block_get_global_vars_from_block($block); + $globals = _fe_block_get_global_settings($block); db_update('block') ->fields($globals) ->condition('module', $block['module']) @@ -911,13 +901,13 @@ function _fe_block_settings_convert($defaults) { $block['node_types'] = $node_types; // Global settings. - $globals = _fe_block_get_global_vars_from_block($defaults['theme'][$theme_default][$block_id]); + $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_specifics_from_block($items[$block_id]); + $block['themes'][$theme] = _fe_block_get_theme_specific_settings($items[$block_id]); } $blocks[$block_id] = $block; } @@ -948,11 +938,11 @@ function _fe_block_settings_convert($defaults) { } // Set theme specific settings. - $blocks[$block_id]['themes'][$theme] = _fe_block_get_theme_specifics_from_block($item); + $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_vars_from_block($item); + $globals = _fe_block_get_global_settings($item); $blocks[$block_id] = array_merge($blocks[$block_id], $globals); } }