You are here

function fasttoggle_get_available_links in Fasttoggle 7

Get all potential links for an object type.

Parameters

string $type: (optional) The object type for which available links are being sought.

object $obj: (optional) An object instance for which available links are being sought. The object's subtype (where applicable) may be used to further filter the links which are returned.

Return value

mixed If the parameter is NULL, an array containing all available links, indexed by type, is returned. If $type if not NULL, only the subtree for that type is returned. In the later case, hooks not supporting the chosen type may skip the work of doing any calculations or calls, saving time andmemory.

3 calls to fasttoggle_get_available_links()
fasttoggle_get_allowed_links in ./fasttoggle.module
Get the list of links the current user may utilise.
fasttoggle_menu in ./fasttoggle.module
Implements hook_menu().
fasttoggle_user_form_alter in module/fasttoggle_user/fasttoggle_user.module
Implements hook_form_alter().

File

./fasttoggle.module, line 295
Enables fast toggling of binary or not so binary settings.

Code

function fasttoggle_get_available_links($type = NULL, $obj = NULL) {
  static $config = array();
  if (empty($config) || !is_null($type) && empty($config[$type])) {

    // The cache is completely empty or the type hasn't been cached.
    if (is_null($type)) {

      // Get all available links.
      $config = module_invoke_all('fasttoggle_available_links');
    }
    else {

      // Just interested in one type.
      $temp = module_invoke_all('fasttoggle_available_links', $type, $obj);
      if (!isset($temp[$type])) {
        $temp[$type] = array();
      }
      if (is_null($obj)) {
        $config[$type] = $temp[$type];
      }
      else {

        // Interested in a particular object. Don't cache.
        return $temp[$type];
      }
    }
  }
  return is_null($type) ? $config : $config[$type];
}