You are here

function styles_instance in Styles 7.2

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

File

./styles.module, line 466
Bundles similar display formatters together.

Code

function styles_instance($variables) {
  static $id = 0;
  $variables['id'] = $id++;
  $field_type = $variables['field_type'];
  $style_name = $variables['style_name'];
  $object = $variables['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['default preset'] = isset($variables['preset_style']['default preset']) ? $variables['preset_style']['default preset'] : (isset($variables['presets']['default preset']) ? $variables['presets']['default preset'] : '');
  $variables['preset'] = isset($variables['preset_style']['selected preset']) ? $variables['preset_style']['selected preset'] : (isset($variables['preset_style']['preset']) ? $variables['preset_style']['preset'] : $variables['default preset']);
  $variables['effects'] = $variables['preset'] !== '' && isset($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);
  }
}