You are here

function widgets_element_definitions in Widgets 7

Pull in widget elements exposed by modules implementing hook_widgets_element_info().

Return value

An array of widget elements to be used when organizing widget sets.

See also

hook_widgets_element_info()

widgets_element_definition_load()

4 calls to widgets_element_definitions()
widgets_definition_features_export_options in ./widgets.features.inc
Implements hook_features_export_options().
widgets_definition_list in ./widgets.admin.inc
Menu callback; Listing of all current widget definitions.
widgets_element_definition_load in ./widgets.module
Load the definition for an widget.
widgets_set_form in ./widgets.admin.inc
Form builder; Edit an widget set name and elements order.

File

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

Code

function widgets_element_definitions() {
  global $language;

  // hook_widgets_element_info() includes translated strings, so each language is
  // cached separately.
  $langcode = $language->language;
  $elements =& drupal_static(__FUNCTION__);
  if (!isset($elements)) {
    if ($cache = cache_get("widgets_elements:{$langcode}") && !empty($cache->data)) {
      $elements = $cache->data;
    }
    else {
      $elements = array();
      include_once drupal_get_path('module', 'widgets') . '/widgets.elements.inc';
      foreach (module_implements('widgets_element_info') as $module) {
        foreach (module_invoke($module, 'widgets_element_info') as $name => $element) {

          // Ensure the current toolkit supports the element.
          $element['module'] = $module;
          $element['name'] = $name;
          $element['data'] = isset($element['data']) ? $element['data'] : array();
          $element['storage'] = WIDGETS_STORAGE_DEFAULT;
          $elements[$name] = $element;
        }
      }

      // Select all the user-defined definitions.
      $user_defs = db_select('widgets_definitions', NULL, array(
        'fetch' => PDO::FETCH_ASSOC,
      ))
        ->fields('widgets_definitions')
        ->orderBy('name')
        ->execute()
        ->fetchAllAssoc('name', PDO::FETCH_ASSOC);
      foreach ($user_defs as $def_name => $def) {
        $def = unserialize($def['data']);
        if (!isset($def['data'])) {
          $def['data'] = array();
        }
        $def['storage'] = WIDGETS_STORAGE_NORMAL;
        $elements[$def_name] = $def;
      }
      uasort($elements, '_widgets_element_definitions_sort');
      drupal_alter('widgets_element_info', $elements);
      cache_set("widgets_elements:{$langcode}", $elements);
    }
  }
  return $elements;
}