You are here

function hhhfile_styles in Styles 7

Build a list of all registered File styles.

Each effect within a style will be attached to a specific mimetype, and will be invoked as required when displaying a file field instance.

To register a new display formatter for a specific mimetype to be made available to the system, you will need to implement hook_file_styles($mimetype).

To register a default, module-defined style of File effects, you will need to implement hook_file_styles_default_styles().

See API.txt for more information.

Return value

This returns an array of all file styles, keyed by the style names.

File

contrib/file_styles/file_styles.module, line 665
File widget formatter definitions.

Code

function hhhfile_styles() {
  $styles =& drupal_static(__FUNCTION__);

  // Grab from cache or build the array.
  if (!isset($styles)) {
    if ($cache = cache_get('file_styles', 'cache')) {
      $styles = $cache->data;
    }
    else {
      $styles = array();

      // Select the module-defined styles.
      foreach (module_implements('file_styles_default_styles') as $module) {
        $module_styles = module_invoke($module, 'file_styles_default_styles');
        foreach ($module_styles as $style_name => $style) {
          $style['name'] = $style_name;
          $style['module'] = $module;
          $style['storage'] = FILE_STORAGE_DEFAULT;
          $styles[$style_name] = $style;
        }
      }

      // Select all the user-defined styles.
      $user_styles = db_select('file_styles', NULL, array(
        'fetch' => PDO::FETCH_ASSOC,
      ))
        ->fields('file_styles')
        ->orderBy('name')
        ->execute()
        ->fetchAllAssoc('name', PDO::FETCH_ASSOC);

      // Allow the user styles to override the module styles.
      foreach ($user_styles as $style_name => $style) {
        $style['module'] = NULL;
        $style['storage'] = FILE_STORAGE_NORMAL;

        // Formatters will be an array of module-defined formatters keyed by
        // mimetype.
        //         $style['formatters'] = unserialize($style['formatters']);
        if (isset($styles[$style_name]['module'])) {
          $style['module'] = $styles[$style_name]['module'];
          $style['storage'] = FILE_STORAGE_OVERRIDE;
        }
        $styles[$style_name] = $style;
      }

      // Allow any module implementing hook_file_style_bundles to alter the styles.
      drupal_alter('file_styles', $styles);
      cache_set('file_styles', $styles);
    }
  }
  return $styles;
}