You are here

function widgets_sets in Widgets 7

Get an array of all sets and their settings.

Return value

array|mixed An array of sets keyed by the widget set ID (wsid).

See also

widgets_set_load()

8 calls to widgets_sets()
widgets_block_info in ./widgets.module
Implements hook_block_info().
widgets_content_type_visibility in ./widgets.module
widgets_set_features_export_options in ./widgets.features.inc
Implements hook_features_export_options().
widgets_set_list in ./widgets.admin.inc
Menu callback; Listing of all current widget sets.
widgets_set_load in ./widgets.module
Load a set by set name or ID. May be used as a loader for menu items.

... See full list

2 string references to 'widgets_sets'
widgets_set_flush in ./widgets.module
Flush cached media for a set.
widgets_set_save in ./widgets.module
Save an widget set.

File

./widgets.module, line 392
Exposes global functionality for creating widget sets.

Code

function widgets_sets() {
  $sets =& drupal_static(__FUNCTION__);

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

      // Select the module-defined sets.
      foreach (module_implements('widgets_default_sets') as $module) {
        $module_sets = module_invoke($module, 'widgets_default_sets');
        foreach ($module_sets as $set_name => $set) {
          $set['name'] = $set_name;
          $set['module'] = $module;
          $set['storage'] = WIDGETS_STORAGE_DEFAULT;
          foreach ($set['elements'] as $key => $element) {
            $definition = widgets_element_definition_load($element['name']);
            if (is_array($definition)) {
              $element = array_merge($definition, $element);
            }
            $set['elements'][$key] = $element;
          }
          $sets[$set_name] = $set;
        }
      }

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

      // Allow the user sets to override the module sets.
      foreach ($user_sets as $set_name => $set) {
        $set['module'] = NULL;
        $set['storage'] = WIDGETS_STORAGE_NORMAL;
        $set['elements'] = widgets_set_elements($set);
        if ($set['data']) {
          $set['data'] = unserialize($set['data']);
        }
        if (isset($sets[$set_name]['module'])) {
          $set['module'] = $sets[$set_name]['module'];
          $set['storage'] = WIDGETS_STORAGE_OVERRIDE;
        }
        $sets[$set_name] = $set;
      }
      drupal_alter('widgets_sets', $sets);
      cache_set('widgets_sets', $sets);
    }
  }
  return $sets;
}