function styles_default_styles in Styles 7.2
Same name and namespace in other branches
- 6.2 styles.module \styles_default_styles()
Return all available styles for a specific field type.
Each style under a field type should be an associative array with the following optional keys: 'description' => An untranslated human readable description for the style. 'default theme' => The theme to call for display if there is no preset returned when filtering the field. 'default theme arguments' => Any arguments to pass after the first (of the field's object itself).
Example implementation of hook_styles_default_styles(): array( 'nodereference' => array( 'styles' => array( 'thumbnail' => array( 'description' => 'Representative thumbnails linking to the content page.', 'default theme' => 'my_styles_default_thumbnail', ), 'small' => array( 'description' => 'Small images linking to the content page.', 'default theme' => 'my_styles_default_thumbnail', ), 'teaser' => array( 'description' => 'A short summary of the content.', 'default theme' => 'node_view', 'default theme arguments' => array(TRUE), ), ), ), );
This will create those styles, allowing
Parameters
string $field_type: (Optional) The field type, such as filefield or nodereference.
boolean $reset: (Optional) If TRUE, then we reset the cache.
13 calls to styles_default_styles()
- file_styles_entity_info_alter in contrib/
file_styles/ file_styles.module - Implements hook_entity_info_alter().
- styles_default_presets in ./
styles.module - Return all available presets for field type containers.
- styles_field_formatter_info in ./
styles.module - Implements hook_field_formatter_info().
- styles_instance in ./
styles.module - styles_style_features_export in includes/
styles.features.inc - Implements hook_features_export().
2 string references to 'styles_default_styles'
- styles_features_api in ./
styles.module - Implements hook_features_api().
- styles_style_flush in ./
styles.module - Flush cached defaults for a style.
File
- ./
styles.module, line 192 - Bundles similar display formatters together.
Code
function styles_default_styles($return_type = NULL, $reset = FALSE) {
$styles =& drupal_static(__FUNCTION__);
// Grab from cache or build the array.
if (!isset($styles) || $reset) {
if (($cache = cache_get('styles_default_styles', 'cache_styles')) && !$reset) {
$styles = $cache->data;
}
else {
$styles = array();
styles_module_load_all_includes();
foreach (module_implements('styles_default_styles') as $module) {
$module_styles = module_invoke($module, 'styles_default_styles');
foreach ($module_styles as $field_type => $container) {
$styles[$field_type] = isset($styles[$field_type]) ? $styles[$field_type] : array();
$containers = isset($styles[$field_type]['styles']) ? $styles[$field_type]['styles'] : array();
$styles[$field_type] = array_merge($styles[$field_type], $container);
$styles[$field_type]['styles'] = isset($styles[$field_type]['styles']) ? $styles[$field_type]['styles'] : array();
$styles[$field_type]['styles'] = array_merge($containers, $styles[$field_type]['styles']);
foreach ($container['styles'] as $style_name => $style) {
$style['name'] = $style_name;
$style['module'] = $module;
$style['storage'] = STYLES_STORAGE_DEFAULT;
$style['field_type'] = $field_type;
$style['description'] = isset($style['description']) ? $style['description'] : '';
$styles[$field_type]['styles'][$style_name] = $style;
}
}
}
// Add user defined & overridden styles next.
$user_styles = db_select('styles', NULL, array(
'fetch' => PDO::FETCH_ASSOC,
))
->fields('styles')
->orderBy('name')
->execute()
->fetchAllAssoc('name', PDO::FETCH_ASSOC);
foreach ($user_styles as $style_name => $style) {
$field_type = $style['field_type'];
$style['module'] = NULL;
$style['storage'] = STYLES_STORAGE_NORMAL;
if (isset($styles[$field_type]['styles'][$style_name]['module'])) {
$style['module'] = $styles[$field_type]['styles'][$style_name]['module'];
$style['storage'] = STYLES_STORAGE_OVERRIDE;
}
$styles[$field_type]['styles'][$style_name] = $style;
}
drupal_alter('styles_default_styles', $styles);
cache_set('styles_default_styles', $styles, 'cache_styles');
}
}
if (isset($return_type)) {
return $styles[$return_type];
}
return $styles;
}