diff --git a/fe_date.module b/fe_date.module index 77a8bd9..c866615 100644 --- a/fe_date.module +++ b/fe_date.module @@ -1,18 +1,22 @@ t('Date format types'), 'feature_source' => TRUE, - 'default_hook' => 'fe_date_date_format_types', + 'default_hook' => 'date_format_types', 'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON, ); + $components['fe_date_custom_date_formats'] = array( 'name' => t('Custom date formats'), 'feature_source' => TRUE, 'default_hook' => 'fe_date_custom_date_formats', 'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON, ); + if (module_exists('locale')) { $components['fe_date_locale_date_format'] = array( 'name' => t('Locale date format'), @@ -39,6 +45,7 @@ function fe_date_features_api() { 'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON, ); } + return $components; } @@ -51,6 +58,7 @@ function fe_date_date_format_types_features_export_options() { foreach ($format_types as $type => $format_type) { $options[$type] = $format_type['title']; } + return $options; } @@ -65,7 +73,7 @@ function fe_date_date_format_types_features_export($data, &$export, $module_name $map_date_format_types = features_get_default_map('fe_date_date_format_types'); foreach ($data as $type) { // Only add format type to export, if it is available. - if ($spec = system_get_date_types($type)) { + if (system_get_date_types($type)) { $variable = 'date_format_' . $type; // Add a dependency when the variable already in a feature but not by use. @@ -79,7 +87,8 @@ function fe_date_date_format_types_features_export($data, &$export, $module_name $default_format = _fe_date_get_default_format($type); - // Add a dependency when the default date format is a custom date format and already in a feature but not by use. + // Add a dependency when the default date format is a custom date format + // and already in a feature but not by use. if (isset($map_custom_formats[$default_format]) && $map_custom_formats[$default_format] != $module_name) { $export['dependencies'][$map_custom_formats[$default_format]] = $map_custom_formats[$default_format]; } @@ -88,7 +97,8 @@ function fe_date_date_format_types_features_export($data, &$export, $module_name $pipe['fe_date_custom_date_formats'][$default_format] = $default_format; } - // Add a dependency when the date_format_type already in a feature but not by use. + // Add a dependency when the date_format_type already in a feature but + // not by use. if (isset($map_date_format_types[$type]) && $map_date_format_types[$type] != $module_name) { $export['dependencies'][$map_date_format_types[$type]] = $map_date_format_types[$type]; } @@ -98,6 +108,7 @@ function fe_date_date_format_types_features_export($data, &$export, $module_name } } + return $pipe; } @@ -119,7 +130,7 @@ function fe_date_date_format_types_features_export_render($module, $data, $expor $code[] = ' return $format_types;'; $code = implode("\n", $code); - return array('fe_date_date_format_types' => $code); + return array('date_format_types' => $code); } /** @@ -138,6 +149,7 @@ function fe_date_locale_date_format_features_export_options() { } } } + return $options; } @@ -154,7 +166,8 @@ function fe_date_locale_date_format_features_export($data, &$export, $module_nam foreach ($data as $name) { list($type, $langcode) = explode('::', $name . '::', 3); if ($format = _fe_date_get_locale_date_format($type, $langcode)) { - // Add a dependency when the type already in a feature but not by use or system. + // Add a dependency when the type already in a feature but not by use + // or system. if (isset($map_date_format_types[$type]) && !in_array($map_date_format_types[$type], array('system', $module_name))) { $export['dependencies'][$map_date_format_types[$type]] = $map_date_format_types[$type]; } @@ -174,12 +187,13 @@ function fe_date_locale_date_format_features_export($data, &$export, $module_nam if (isset($map_locale_date_format[$name]) && $map_locale_date_format[$name] != $module_name) { $export['dependencies'][$map_locale_date_format[$name]] = $map_locale_date_format[$name]; } - else{ - // Add format to exports + else { + // Add format to exports. $export['features']['fe_date_locale_date_format'][$name] = $name; } } } + return $pipe; } @@ -191,7 +205,7 @@ function fe_date_locale_date_format_features_export_render($module, $data, $expo $code[] = ' $locale_date_formats = array();'; $code[] = ''; foreach ($data as $name) { - list($type, $langcode) = explode('::', $name .'::', 3); + list($type, $langcode) = explode('::', $name . '::', 3); if ($format = _fe_date_get_locale_date_format($type, $langcode)) { $var = array( 'type' => $type, @@ -207,6 +221,7 @@ function fe_date_locale_date_format_features_export_render($module, $data, $expo $code[] = ' return $locale_date_formats;'; $code = implode("\n", $code); + return array('fe_date_locale_date_format' => $code); } @@ -222,13 +237,13 @@ function fe_date_locale_date_format_features_revert($module) { * * hook_date_formats() is used to define the necessary formats, but the * association to the date format type is not set by using that hook. So we have - * to set it in the database by ourselfs. + * to set it in the database by ourselves. * * @see hook_date_formats() */ function fe_date_locale_date_format_features_rebuild($module) { if ($defaults = features_get_default('fe_date_locale_date_format', $module)) { - foreach ($defaults as $key => $spec) { + foreach ($defaults as $spec) { foreach ($spec['locales'] as $locale) { locale_date_format_save($locale, $spec['type'], $spec['format']); } @@ -240,7 +255,7 @@ function fe_date_locale_date_format_features_rebuild($module) { * Helper function to get the pure format (locale or from variable). */ function _fe_date_get_locale_date_format($type, $langcode) { - // Try to get a locale date format + // Try to get a locale date format. $format = system_date_format_locale($langcode, $type); // If no format was found, we get the default value. if (empty($format)) { @@ -255,6 +270,7 @@ function _fe_date_get_locale_date_format($type, $langcode) { function _fe_date_get_default_format($type) { // Do not use variable_get() as this may fetch an already localized variable. $format = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'date_format_' . $type))->fetchField(); + return ($format !== FALSE) ? unserialize($format) : NULL; } @@ -265,10 +281,11 @@ function fe_date_custom_date_formats_features_export_options() { $formats = system_get_date_formats('custom'); $options = array(); if (!empty($formats)) { - foreach ($formats as $format => $format_data) { + foreach (array_keys($formats) as $format) { $options[$format] = $format; } } + return $options; } @@ -283,10 +300,11 @@ function fe_date_custom_date_formats_features_export($data, &$export, $module_na if (!empty($map[$format]) && $map[$format] != $module_name) { $export['dependencies'][$map[$format]] = $map[$format]; } - else{ + else { $export['features']['fe_date_custom_date_formats'][$format] = $format; } } + return array(); } @@ -305,6 +323,7 @@ function fe_date_custom_date_formats_features_export_render($module, $data, $exp } $code[] = ' return $custom_date_formats;'; $code = implode("\n", $code); + return array('fe_date_custom_date_formats' => $code); } @@ -332,4 +351,3 @@ function fe_date_custom_date_formats_features_revert($module) { } } } -