You are here

function styles_default_containers in Styles 6.2

Same name and namespace in other branches
  1. 7.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 $field_type: (Optional) The field type, such as filefield or nodereference.

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

4 calls to styles_default_containers()
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.
styles_ui_help in contrib/styles_ui/styles_ui.module
Implementation of hook_help().
xstyles_ui_menu in contrib/styles_ui/styles_ui.module
Implementation of hook_menu().

File

./styles.module, line 105
styles.module Styles

Code

function styles_default_containers($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_containers', 'cache')) && !$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] = $container;
          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;
          }
        }
      }

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