You are here

function entityform_get_types in Entityform 7.2

Same name and namespace in other branches
  1. 7 entityform.module \entityform_get_types()

Gets an array of all entityform types, keyed by the type name.

Parameters

$type_name: If set, the type with the given name is returned.

Return value

EntityformType[] Depending whether $type isset, an array of entityform types or a single one.

7 calls to entityform_get_types()
EntityformController::create in ./entityform.module
Create a entityform - we first set up the values that are specific to our entityform schema but then also go through the EntityAPIController function.
EntityformUIController::hook_menu in ./entityform.admin.inc
Overrides hook_menu() defaults. Main reason for doing this is that parent class hook_menu() is optimized for entity type administration.
entityform_forms in ./entityform.module
Implements hook_forms().
entityform_mollom_form_list in ./entityform.module
Implements hook_mollom_form_list().
entityform_page_title in ./entityform.module
Menu title callback for showing individual entities

... See full list

1 string reference to 'entityform_get_types'
entityform_type_cache_reset in ./entityform.module
Clears the entityform type cache.

File

./entityform.module, line 369
Module for the Entityform Entity - a starting point to create your own Entity and associated administration interface

Code

function entityform_get_types($type_name = NULL) {

  // entity_load will get the Entity controller for our entityform entity and call the load
  // function of that object - we are loading entities by name here.
  // Use the advanced drupal_static() pattern since this is called very often.
  static $drupal_static_fast;
  $cache_key = 'entityform_types';
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast[$cache_key] =& drupal_static(__FUNCTION__);
  }
  $entityform_types =& $drupal_static_fast[$cache_key];
  if (empty($entityform_types)) {
    if ($cache = cache_get($cache_key)) {
      $entityform_types = $cache->data;
    }
  }

  // $entityform_types may be set but might not have our $type_name if called first for other $type_name
  // @todo What if it is called first with $type_name set and then called without $type_name set.
  //  wouldn't it return a single element array even if there were more entityform types.
  if (empty($entityform_types) || isset($type_name) && empty($entityform_types[$type_name])) {
    if (!isset($type_name)) {
      $entityform_types = entity_load_multiple_by_name('entityform_type', FALSE);
    }
    else {
      $types = entity_load_multiple_by_name('entityform_type', array(
        $type_name,
      ));
      if (empty($types)) {
        return FALSE;
      }
      $entityform_types[$type_name] = array_shift($types);
    }
    if (!isset($type_name)) {

      // Only set the cache if retrieved all entityform types.
      cache_set($cache_key, $entityform_types);
    }
  }
  if (isset($type_name)) {

    // Even though $type_name was set it might not be valid
    return isset($entityform_types[$type_name]) ? $entityform_types[$type_name] : NULL;
  }
  return $entityform_types;
}