You are here

function salesforce_mapping_menu in Salesforce Suite 7.3

Implements hook_menu().

File

modules/salesforce_mapping/salesforce_mapping.module, line 158

Code

function salesforce_mapping_menu() {
  $items = array();
  $items['admin/content/salesforce'] = array(
    'title' => 'Salesforce Mapped Objects',
    'description' => 'Manage mapped Salesforce objects.',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'salesforce_mapping_object_overview_page',
    'file' => 'includes/salesforce_mapping_object.admin.inc',
    'access arguments' => array(
      'view salesforce mapping object',
    ),
  );

  // Define SF activity local tasks for all mapped entities.
  $defaults = array(
    'file' => 'salesforce_mapping_object.admin.inc',
    'file path' => drupal_get_path('module', 'salesforce_mapping') . '/includes',
  );
  $mappings = salesforce_mapping_load();
  $mapped_entities = array();
  foreach ($mappings as $mapping) {

    // We grab the bundle now because it becomes inaccessible for some entities
    // after it is put into the loop below:
    $mapped_entities[$mapping->drupal_entity_type] = $mapping->drupal_bundle;
  }
  $manual_uris = array();
  drupal_alter('salesforce_mapping_entity_uris', $manual_uris);
  foreach ($mapped_entities as $type => $bundle) {
    $uri = array();
    if (isset($manual_uris[$type])) {
      $uri = $manual_uris[$type];
    }
    else {
      try {
        $info = entity_get_info($type);
        $bundle_key = $info['entity keys']['bundle'] ?: 'type';
        $entity = entity_create($type, array(
          $bundle_key => $bundle,
        ));
        $uri = method_exists($entity, 'uri') ? $entity
          ->uri() : entity_uri($type, $entity);
      } catch (Exception $e) {

        // Fall through to default behavior
      }
    }
    if (empty($uri['path'])) {
      $path = 'admin/content/salesforce/' . $type . '/%' . $type . '/salesforce_activity';
      $menu_type = MENU_NORMAL_ITEM;
    }
    else {
      $path = $uri['path'] . '%' . $type . '/salesforce_activity';
      $menu_type = MENU_LOCAL_TASK;
    }
    $entity_arg = substr_count($path, '/') - 1;
    $items[$path] = array(
      'title' => 'Salesforce activity',
      'description' => 'View Salesforce activity for this entity.',
      'type' => $menu_type,
      'page callback' => 'salesforce_mapping_object_view',
      'page arguments' => array(
        $entity_arg,
        $type,
      ),
      'access callback' => 'salesforce_mapping_entity_mapping_accessible',
      'access arguments' => array(
        'view',
        $entity_arg,
        $type,
      ),
    );
    $items[$path . '/view'] = array(
      'title' => 'View',
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[$path . '/edit'] = array(
      'page callback' => 'salesforce_mapping_object_edit',
      'page arguments' => array(
        $entity_arg,
        $type,
      ),
      'access arguments' => array(
        'edit salesforce mapping object',
      ),
      'title' => 'Edit',
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    ) + $defaults;
    $items[$path . '/delete'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'salesforce_mapping_object_delete_form',
        $entity_arg,
        $type,
      ),
      'access arguments' => array(
        'delete salesforce mapping object',
      ),
      'title' => 'Delete',
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_INLINE,
    );
  }

  // Provide a default Delete location, in case a mapping gets orphaned.
  $items['admin/content/salesforce/%/delete'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'salesforce_mapping_universal_object_delete_form',
      3,
    ),
    'access arguments' => array(
      'delete salesforce mapping object',
    ),
    'title' => 'Delete',
    'type' => MENU_NORMAL_ITEM,
    'context' => MENU_CONTEXT_INLINE,
  );
  return $items;
}