You are here

function entityconnect_form_alter in Entity connect 7.2

Same name and namespace in other branches
  1. 8.2 entityconnect.module \entityconnect_form_alter()
  2. 7 entityconnect.module \entityconnect_form_alter()

Implements hook_form_alter().

If we are adding a new entity we pass of to entityconnect_add_form_alter if we are returning to the parent form we hand off to entityconnect_return_form_alter.

File

./entityconnect.module, line 171
Handles the main hooks used by entityconnect.

Code

function entityconnect_form_alter(&$form, &$form_state, $form_id) {
  $child = isset($_REQUEST['child']);

  // We can get the cid two different ways
  // first we try the $_REQUEST param.  if we do not getting it from there we
  // try the arg(3) if we are on a add form.  Also if we are on an add form we
  // know that we are a child page.
  foreach (arg() as $key => $value) {
    if (stripos($value, 'entityconnect-form-', 0) === 0) {
      $cid = $value;
    }
  }
  if (isset($_REQUEST['build_cache_id']) && ($cid = $_REQUEST['build_cache_id']) || isset($cid) && ($child = TRUE)) {
    $cache = entityconnect_cache_get($cid);
    entityconnect_include_form();
    if ($child) {
      $form_state['#entityconnect_child_form'] = $cache;
    }
    if (isset($_REQUEST['return']) && isset($cache->data) && $cache->data['form']['#form_id'] == $form_id) {
      unset($_REQUEST['build_cache_id']);
      entityconnect_return_form_alter($form, $form_state, $form_id, $cid, $cache);
    }
  }

  // If this form is a child form let's add alter for that purpose
  // Note that we are doing this here becuase when we retrun to a form it gets
  // rebuilt so this will get caught in the rebuilt.
  if (isset($form_state['#entityconnect_child_form']) && $form_state['#entityconnect_child_form']) {
    $cache = $form_state['#entityconnect_child_form'];
    module_load_include('inc', 'entityconnect', 'includes/entityconnect.form');
    entityconnect_child_form_alter($form, $form_state, $form_id, $cache->cid, $cache);
  }
}