You are here

function icon_bundles in Icon API 7

Same name and namespace in other branches
  1. 8 icon.module \icon_bundles()

Returns information about all icon bundles.

Parameters

string $name: The name of the bundle to load.

bool $reset: Boolean to force reset of the cached data. Default: FALSE.

Return value

array|false An associative array containing information for all bundles.

See also

hook_icon_info()

7 calls to icon_bundles()
form_process_icon_selector in includes/element.inc
Processes an icon select list form element.
icon_bundle_load in ./icon.module
Load a specific bundle.
icon_bundle_overview_form in includes/admin.inc
Menu callback for 'icon_bundle_overview_form'.
icon_bundle_overview_form_submit in includes/admin.inc
Submit callback for 'icon_bundle_overview_form'.
icon_clear_all_caches in includes/cache.inc
Clears all caches used by the icon module.

... See full list

2 string references to 'icon_bundles'
icon_hook_info in ./icon.module
Implements hook_hook_info().
icon_reset_static_cache in includes/cache.inc
Clears all static caches used by the icon module.

File

./icon.module, line 303
icon.module Provides icon integration with menu items.

Code

function icon_bundles($name = NULL, $reset = FALSE) {
  $bundles =& drupal_static(__FUNCTION__);
  if (!isset($bundles) || $reset) {
    if (!$reset && ($cache = cache_get('icon_bundles')) && !empty($cache->data)) {
      $bundles = $cache->data;
    }
    else {
      $bundles = array();

      // Gather information from extensions that implement hook_icon_bundles().
      foreach (icon_extension_implements('icon_bundles') as $extension => $type) {
        $extension_bundles = (array) icon_extension_invoke($type, $extension, 'icon_bundles');
        foreach ($extension_bundles as $bundle_name => $bundle) {
          icon_bundle_defaults($bundle, $bundle_name);
          if (empty($bundle['provider'])) {
            $bundle['provider'] = $extension;
          }

          // Alphabetically sort the icons.
          if (!empty($bundle['icons'])) {
            ksort($bundle['icons']);
          }

          // In cases where themes may provide sprite icons (such as Bootstrap),
          // we need to specify the theme to use for this bundle. These types
          // of bundles do not attach a separate CSS file with the bundle and
          // the sprite classes are instead, generated with the theme's CSS.
          // @see icon_bundle_get_theme()
          // @see icon_menu().
          if ($type === 'theme' && $bundle['render'] === 'sprite' && empty($bundle['#attached']['css'])) {
            $bundle['theme'] = $extension;
          }
          $bundles[$bundle_name] = $bundle;
        }
      }

      // Gather database bundles (which overrides any module implementations).
      $database_bundles = db_select('icon_bundle', 'b')
        ->fields('b')
        ->execute();
      foreach ($database_bundles as $database_bundle) {
        $bundle = unserialize($database_bundle->bundle);
        if ($bundle === FALSE) {
          $bundle = array();
        }
        else {
          icon_bundle_defaults($bundle, $bundle['name']);
          if (!empty($bundles[$database_bundle->name])) {
            $bundle['overridden'] = TRUE;
          }
        }
        $bundle['database'] = TRUE;
        $bundle['status'] = (int) $database_bundle->status;
        if (isset($bundles[$database_bundle->name])) {
          $bundle = array_merge($bundles[$database_bundle->name], $bundle);
        }
        $bundles[$database_bundle->name] = $bundle;
      }

      // Allow extensions to alter the bundles.
      drupal_alter('icon_bundles', $bundles);

      // Cache the info.
      cache_set('icon_bundles', $bundles);
    }
  }
  if (isset($name)) {
    if (!empty($bundles[$name])) {
      return $bundles[$name];
    }
    else {
      $false = FALSE;
      return $false;
    }
  }
  return $bundles;
}