You are here

function styles_default_presets in Styles 6.2

Same name and namespace in other branches
  1. 7.2 styles.module \styles_default_presets()

Return all available presets for field type containers.

Each container under a field type should be an associative array with the following keys: 'default preset' => The preset to select by default, which may be overridden later. 'presets' => An associative array keyed by the preset name, each with an array of effects to be passed to the implementing class on display.

Example implementation of hook_styles_default_presets(): array( 'filefield' => array( 'containers' => array( 'imagefield' => array( 'default preset' => 'imagecache_thumbnail_linked', 'presets' => array( 'imagecache_thumbnail_linked' => array( 'title' => '[node-title]', 'alt' => '[file-description]', 'imagecache_preset' => 'thumbnail', 'link' => '[node-path]', ), 'link_to_file' => array( 'title' => '[file-title-raw]', 'link' => '[file-path]', ), ), ), ), );

Parameters

string $field_type: (Optional) The field type, such as filefield or nodereference.

boolean $reset: (Optional) If TRUE, then we reset the cache.

3 calls to styles_default_presets()
styles_instance in ./styles.module
styles_ui_containers_overview in contrib/styles_ui/includes/styles_ui.admin.inc
Page callback for various styles preset overview listing pages.
xstyles_ui_menu in contrib/styles_ui/styles_ui.module
Implementation of hook_menu().

File

./styles.module, line 255
styles.module Styles

Code

function styles_default_presets($return_type = NULL, $reset = FALSE) {
  $styles =& _styles_drupal_static(__FUNCTION__);

  // Grab from cache or build the array.
  if (!isset($styles) || $reset) {
    if (($cache = cache_get('styles_default_presets', 'cache')) && !$reset) {
      $styles = $cache->data;
    }
    else {
      $styles = array();
      styles_module_load_all_includes();
      foreach (module_implements('styles_default_presets') as $module) {
        $module_styles = module_invoke($module, 'styles_default_presets');
        foreach ($module_styles as $field_type => $container) {
          $all_styles = styles_default_styles($field_type);
          $styles[$field_type] = $container;
          foreach ($container['containers'] as $style_name => $style) {
            $style['name'] = $style_name;
            $style['module'] = $module;
            $style['storage'] = STYLES_STORAGE_DEFAULT;
            $style['styles'] = isset($style['styles']) ? $style['styles'] : array();
            $default_preset = isset($style['default preset']) ? $style['default preset'] : '';
            foreach ($all_styles['styles'] as $container_style_name => $container_style) {
              if (!isset($style['styles'][$container_style_name])) {
                $style['styles'][$container_style_name] = array(
                  'default preset' => $default_preset,
                );
              }
            }
            $styles[$field_type]['containers'][$style_name] = $style;
          }
        }
      }

      // @TODO: Add user styles next.
      drupal_alter('styles_default_presets', $styles);
      cache_set('styles_default_presets', $styles);
    }
  }
  if (isset($return_type)) {
    return $styles[$return_type];
  }
  return $styles;
}