You are here

function styles_default_containers in Styles 7.2

Same name and namespace in other branches
  1. 6.2 styles.module \styles_default_containers()

Return all available containers for a specific field type.

Modules implementing this hook should supply an array for each field type that it supports, with at least two keys: 'containers', containing an associated array described below, and 'filter callback' => A function to call with the field object to determine which container to implement.

Each container under a field type should be an associative array with the following keys: 'class' => The class to instantiate when filtering to this container. 'filter match' => (Optional) A value to pass to the filter callback to match the field object against this container.

Example implementation of hook_styles_default_containers(): array( 'emvideo' => array( 'filter callback' => 'my_styles_emvideo_filter', 'containers' => array( 'brightcove' => array( 'class' => 'BrightcoveStyles', 'filter match' => array('brightcove'), ), 'vimeo' => array( 'class' => 'VimeoStyles', 'filter match' => array('vimeo'), ), 'youtube' => array( 'class' => 'YouTubeStyles', 'filter match' => array('youtube', 'my_youtube'), ), ), ), );

Parameters

string $return_type: (Optional) The field type, such as file or nodereference.

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

10 calls to styles_default_containers()
file_styles_styles_filter in contrib/file_styles/file_styles.module
Styles filter callback.
styles_instance in ./styles.module
styles_ui_containers_overview in contrib/styles_ui/styles_ui.admin.inc
Page callback for various styles overview listing pages.
styles_ui_delete_confirm in contrib/styles_ui/styles_ui.admin.inc
Menu callback; delete a style.
styles_ui_delete_confirm_submit in contrib/styles_ui/styles_ui.admin.inc
Process style delete confirm submissions.

... See full list

1 string reference to 'styles_default_containers'
styles_style_flush in ./styles.module
Flush cached defaults for a style.

File

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

Code

function styles_default_containers($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_containers', 'cache_styles')) && !$reset) {
      $styles = $cache->data;
    }
    else {
      $styles = array();
      styles_module_load_all_includes();
      foreach (module_implements('styles_default_containers') as $module) {
        $module_styles = module_invoke($module, 'styles_default_containers');
        foreach ($module_styles as $field_type => $container) {
          $styles[$field_type] = isset($styles[$field_type]) ? $styles[$field_type] : array();

          // Pull out existing containers before the merge.
          $containers = isset($styles[$field_type]['containers']) ? $styles[$field_type]['containers'] : array();

          // Merge in the module defined containers.
          $styles[$field_type] = array_merge($styles[$field_type], $container);
          $styles[$field_type]['containers'] = isset($styles[$field_type]['containers']) ? $styles[$field_type]['containers'] : array();
          $styles[$field_type]['containers'] = array_merge($containers, $styles[$field_type]['containers']);
          foreach ($container['containers'] as $style_name => $style) {
            $style['name'] = $style_name;
            $style['module'] = $module;
            $style['storage'] = STYLES_STORAGE_DEFAULT;
            $styles[$field_type]['containers'][$style_name] = $style;
          }
        }
      }
      drupal_alter('styles_default_containers', $styles);
      cache_set('styles_default_containers', $styles, 'cache_styles');
    }
  }
  if (isset($return_type)) {
    return $styles[$return_type];
  }
  return $styles;
}