You are here

function entityconnect_child_form_alter in Entity connect 7

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

Alters child create form.

We add a value field to hold the parent build_cache_id then we add a cancel button that run entityconnect_child_form_cancel and a new submit button.

1 call to entityconnect_child_form_alter()
entityconnect_form_alter in ./entityconnect.module
Implements hook_form_alter().

File

includes/entityconnect.form.inc, line 913
Handles all form alters and submit functions for entityconnect.

Code

function entityconnect_child_form_alter(&$form, &$form_state, $form_id, $cache_id, $cache) {

  // Exclude some forms to be processed.
  $exclude_forms = array(
    'search_block_form',
  );

  // Allow other modules to alter exclude forms list.
  drupal_alter('entityconnect_exclude_forms', $exclude_forms);
  if (in_array($form_id, $exclude_forms)) {
    return;
  }
  $form['parent_build_cache_id'] = array(
    '#type' => 'value',
    '#value' => $cache_id,
  );
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#submit' => array(
      'entityconnect_include_form',
      'entityconnect_child_form_cancel',
    ),
    '#parent_build_cache_id' => $cache_id,
    '#limit_validation_errors' => array(),
    '#weight' => 1000,
  );
  switch ($form_id) {
    case 'user_register_form':
      $form['actions']['submit']['#submit'][] = 'user_register_submit';
      break;
    case 'user_profile_form':
      $form['actions']['submit']['#submit'][] = 'user_profile_form_submit';
      break;
    case 'taxonomy_form_term':
      $form['actions']['submit']['#submit'][] = 'taxonomy_form_term_submit';
      break;
    case 'taxonomy_form_vocabulary':
      $form['actions']['submit']['#submit'][] = 'taxonomy_form_vocabulary_submit';
      break;
    case 'node_delete_confirm':
      $form['actions']['submit']['#submit'] = $form['#submit'];
      $form['#submit'] = array();
      break;
    default:
      if (isset($form['#entity_type']) && isset($form['#bundle'])) {

        // Add support for ECK.
        if ('eck__entity__form_add_' . $form['#entity_type'] . '_' . $form['#bundle'] == $form_id || 'eck__entity__form_edit_' . $form['#entity_type'] . '_' . $form['#bundle'] == $form_id) {
          $form['actions']['cancel']['#weight'] = 10001;
          $form['actions']['submit']['#submit'][] = 'eck__entity__form_submit';

          // @todo I think we don't need #submit any more..?
          $form['#submit'] = array();
        }
      }
      break;
  }
  if (isset($form['submit']['#submit'])) {
    $form['submit']['#submit'][] = 'entityconnect_include_form';
    $form['submit']['#submit'][] = 'entityconnect_child_form_submit';
  }
  else {
    $form['actions']['submit']['#submit'][] = 'entityconnect_include_form';
    $form['actions']['submit']['#submit'][] = 'entityconnect_child_form_submit';
  }
  if (strpos($form_id, '_delete_confirm') === false) {
    $form['actions']['delete']['#submit'][] = 'entityconnect_include_form';
    $form['actions']['delete']['#submit'][] = 'entityconnect_child_form_delete_submit';
  }
}