You are here

function entityconnect_edit in Entity connect 7

Same name and namespace in other branches
  1. 7.2 includes/entityconnect.menu.inc \entityconnect_edit()

Page callback: Redirect to edit form.

We use this to redirect to a edit form but pass the build_cache_id.

1 string reference to 'entityconnect_edit'
entityconnect_menu in ./entityconnect.module
Implements hook_menu().

File

includes/entityconnect.menu.inc, line 215
Handles all entityconnect menu item page callbacks.

Code

function entityconnect_edit($cache_id) {
  $cache = entityconnect_cache_get($cache_id);
  $entity_type = $cache->data['target_entity_type'];
  $target_id = $cache->data['target_id'];
  $output = '';
  switch ($entity_type) {
    case 'node':
      if (is_array($target_id)) {
        $info = entity_load($entity_type, $target_id);
        foreach ($info as $key => $value) {
          $content[$key] = array(
            'label' => $value->title,
            'href' => 'node/' . $value->nid . '/edit',
            'description' => '',
          );
        }
        $output = theme('entityconnect_entity_add_list', array(
          'items' => $content,
          'cache id' => $cache_id,
        ));
        $output .= l(t('Cancel'), "admin/entityconnect/return/{$cache_id}");
      }
      else {
        drupal_goto("node/" . $cache->data['target_id'] . "/edit", array(
          'query' => array(
            "build_cache_id" => $cache_id,
            "child" => TRUE,
          ),
        ));
      }
      break;
    case 'user':
      if (is_array($target_id)) {
        $info = entity_load($entity_type, $target_id);
        foreach ($info as $key => $value) {
          $content[$key] = array(
            'label' => $value->name,
            'href' => 'user/' . $value->uid . '/edit',
            'description' => '',
          );
        }
        $output = theme('entityconnect_entity_add_list', array(
          'items' => $content,
          'cache id' => $cache_id,
        ));
        $output .= l(t('Cancel'), "admin/entityconnect/return/{$cache_id}");
      }
      else {
        drupal_goto("user/" . $cache->data['target_id'] . "/edit", array(
          'query' => array(
            "build_cache_id" => $cache_id,
            "child" => TRUE,
          ),
        ));
      }
      break;
    case 'taxonomy_term':
      if (is_array($target_id)) {
        $info = entity_load($entity_type, $target_id);
        foreach ($info as $key => $value) {
          $content[$key] = array(
            'label' => $value->name,
            'href' => 'taxonomy/term/' . $value->tid . '/edit',
            'description' => '',
          );
        }
        $output = theme('entityconnect_entity_add_list', array(
          'items' => $content,
          'cache id' => $cache_id,
        ));
        $output .= l(t('Cancel'), "admin/entityconnect/return/{$cache_id}");
      }
      else {
        drupal_goto("taxonomy/term/" . $cache->data['target_id'] . "/edit", array(
          'query' => array(
            "build_cache_id" => $cache_id,
            "child" => TRUE,
          ),
        ));
      }
      break;
    case 'taxonomy_vocabulary':
      if (is_array($target_id)) {
        $info = entity_load($entity_type, $target_id);
        foreach ($info as $key => $value) {
          $content[$key] = array(
            'label' => $value->name,
            'href' => 'admin/structure/taxonomy/' . $value->name . '/edit',
            'description' => '',
          );
        }
        $output = theme('entityconnect_entity_add_list', array(
          'items' => $content,
          'cache id' => $cache_id,
        ));
        $output .= l(t('Cancel'), "admin/entityconnect/return/{$cache_id}");
      }
      else {
        $info = entity_load_single($entity_type, $target_id);
        drupal_goto("admin/structure/taxonomy/" . $info->name . "/edit", array(
          'query' => array(
            "build_cache_id" => $cache_id,
            "child" => TRUE,
          ),
        ));
      }
      break;
    default:

      // Support for entity construction kit.
      if (module_exists('eck')) {
        $entity_info = entity_get_info($entity_type);
        if ($entity_info['module'] == 'eck') {
          if (is_array($target_id)) {
            $eck_entities = entity_load($entity_type, $target_id);
            foreach ($eck_entities as $key => $eck_entity) {
              $crud_edit_path = preg_replace('/\\%/', $key, $entity_info['bundles'][$eck_entity->type]['crud']['edit']['path']);
              $content[$key] = array(
                'label' => $eck_entity->title,
                'href' => $crud_edit_path,
                'description' => '',
              );
            }
            $output = theme('entityconnect_entity_add_list', array(
              'items' => $content,
              'cache id' => $cache_id,
            ));
            $output .= l(t('Cancel'), "admin/entityconnect/return/{$cache_id}");
          }
          else {
            $eck_entity = entity_load_single($entity_type, $target_id);
            $crud_edit_path = preg_replace('/\\%/', $target_id, $entity_info['bundles'][$eck_entity->type]['crud']['edit']['path']);
            drupal_goto($crud_edit_path, array(
              'query' => array(
                "build_cache_id" => $cache_id,
                "child" => TRUE,
              ),
            ));
          }
        }
      }

      // Support for Bean module..
      if (module_exists('bean_admin_ui')) {
        $entity_info = entity_get_info($entity_type);
        if ($entity_info['module'] == 'bean') {
          if (is_array($target_id)) {
            $info = entity_load($entity_type, $target_id);
            foreach ($info as $key => $value) {
              $content[$key] = array(
                'label' => $value->label,
                'href' => 'block/' . $value->delta . '/edit',
                'description' => '',
              );
            }
            $output = theme('entityconnect_entity_add_list', array(
              'items' => $content,
              'cache id' => $cache_id,
            ));
            $output .= l(t('Cancel'), "admin/entityconnect/return/{$cache_id}");
          }
          else {
            $bean_entity = entity_load_single($entity_type, $target_id);
            drupal_goto("block/" . $bean_entity->delta . "/edit", array(
              'query' => array(
                "build_cache_id" => $cache_id,
                "child" => TRUE,
              ),
            ));
          }
        }
      }
      break;
  }
  return $output;
}