You are here

function styles_instance in Styles 6.2

Same name and namespace in other branches
  1. 7.2 styles.module \styles_instance()
1 call to styles_instance()
template_preprocess_styles in themes/styles.theme.inc

File

./styles.module, line 440
styles.module Styles

Code

function styles_instance($field_type, $style_name, $object) {
  $variables = array(
    'field_type' => $field_type,
    'style_name' => $style_name,
    'object' => $object,
  );

  // Grab the containers for this field type.
  $containers = styles_default_containers($field_type);
  $variables['containers'] = $containers['containers'];
  $callback = $containers['filter callback'];

  // Find the correct container for this field type's styles.
  if (function_exists($callback)) {
    $container = call_user_func_array($callback, array(
      $variables['object'],
      $variables,
    ));
    $variables['container'] = $container && isset($variables['containers'][$container]) ? $variables['containers'][$container] : array();
  }
  else {
    $variables['container'] = array();
  }

  // Grab the styles.
  $styles = styles_default_styles($field_type);
  $variables['styles'] = $styles['styles'];
  $variables['style'] = $style_name && isset($variables['styles'][$style_name]) ? $variables['styles'][$style_name] : array();

  // Grab the presets.
  $presets = styles_default_presets($field_type);
  $variables['presets'] = $container && isset($presets['containers'][$container]) ? $presets['containers'][$container] : array();
  $variables['preset_style'] = isset($variables['presets']['styles'][$style_name]) ? $variables['presets']['styles'][$style_name] : array();
  $variables['preset'] = isset($variables['preset_style']['selected preset']) ? $variables['preset_style']['selected preset'] : (isset($variables['preset_style']['default preset']) ? $variables['preset_style']['default preset'] : (isset($variables['presets']['default preset']) ? $variables['presets']['default preset'] : ''));
  $variables['effects'] = $variables['preset'] !== '' && $variables['presets']['presets'][$variables['preset']] ? $variables['presets']['presets'][$variables['preset']] : array();

  // Instantiate the class and render the output.
  if ($class = $variables['container']['class']) {
    return new $variables['container']['class']($variables['object'], $variables['effects'], $variables);
  }
}