You are here

function sf_entity_menu in Salesforce Suite 7

Same name and namespace in other branches
  1. 7.2 sf_entity/sf_entity.module \sf_entity_menu()

Implements hook_menu(). Create a %/salesforce menu callback for all fieldable entities.

File

sf_entity/sf_entity.module, line 12
Integrates fieldable entities with the Salesforce API.

Code

function sf_entity_menu() {
  $entities = field_info_bundles();
  $items = array();
  foreach ($entities as $entity => $bundles) {
    $info = entity_get_info($entity);
    if (empty($info) || empty($info['fieldable'])) {
      continue;
    }
    $fake_ids = array(
      '__ENTITY_ID__',
      '__ENTITY_VID__',
      '__ENTITY_BUNDLE__',
    );
    if (!$info['entity keys']['revision']) {
      $fake_ids[1] = NULL;
    }
    $stub = entity_create_stub_entity($entity, $fake_ids);
    $uri_callback = $info['uri callback'];
    if (empty($uri_callback)) {
      continue;
    }
    $uri = $uri_callback($stub);
    $parts = explode('/', $uri['path']);
    $page_args = array(
      'sf_entity_salesforce_form',
      $entity,
    );
    $access_args = array(
      $entity,
    );
    foreach ($parts as $i => $part) {
      if ($part == '__ENTITY_ID__') {
        $parts[$i] = '%' . $entity;
        $page_args[] = $i;
        $access_args[] = $i;
      }
      elseif ($part == '__ENTITY_VID__' || $part == '__ENTITY_BUNDLE__') {
        $parts[$i] = '%';
      }
    }
    $parts[] = 'salesforce';
    $uri = implode('/', $parts);
    $items[$uri] = array(
      'title' => 'Salesforce',
      'page callback' => 'drupal_get_form',
      'page arguments' => $page_args,
      'access callback' => 'sf_entity_salesforce_form_access',
      'access arguments' => $access_args,
      'type' => MENU_LOCAL_TASK,
    );
  }
  return $items;
}