You are here

function addtocal_get_addtocal_entities in Add to Cal 7

Returns a list of all eligible entities to use with Add to Cal, along with their eligible fields and matching view modes.

Output structure: [$entity_name][$field_name][$view_mode_name]

Return value

array

3 calls to addtocal_get_addtocal_entities()
addtocal_menu in ./addtocal.module
Implements hook_menu().
addtocal_tokens in ./addtocal.tokens.inc
Implements hook_tokens().
addtocal_token_info_alter in ./addtocal.tokens.inc
Implements hook_token_info_alter().

File

./addtocal.module, line 64
addtocal.module General functions and hook implementations.

Code

function addtocal_get_addtocal_entities() {
  $entities = field_info_instances();
  $entity_info = array();
  foreach ($entities as $entity_name => $entity) {
    foreach ($entity as $bundle_name => $bundle) {
      foreach ($bundle as $field_name => $field) {
        foreach ($field['display'] as $display_name => $display) {
          if ($display['type'] == 'addtocal_view') {

            // This awkward elif structures the output
            if (!array_key_exists($entity_name, $entity_info)) {
              $entity_info[$entity_name] = array(
                $field_name => array(
                  $display_name,
                ),
              );
            }
            else {
              if (!array_key_exists($field_name, $entity_info[$entity_name])) {
                $entity_info[$entity_name][$field_name] = array(
                  $display_name,
                );
              }
              else {
                if (!array_key_exists($display_name, $entity_info[$entity_name][$field_name])) {
                  $entity_info[$entity_name][$field_name][] = $display_name;
                }
              }
            }
          }
        }
      }
    }
  }
  return $entity_info;
}