You are here

function _nodeconnect_field_attach_form in Node Connect 7

Implements of hook_field_attach_form().

here we attach a submit button for each node ref field

1 call to _nodeconnect_field_attach_form()
nodeconnect_field_attach_form in ./nodeconnect.module
Implements hook_field_attache_form().

File

./nodeconnect.form.inc, line 12
handles all form alters and submit functions for nodeconnect

Code

function _nodeconnect_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = LANGUAGE_NONE, $field_name, $field) {
  $language = $form[$field_name]['#language'];
  foreach ($form[$field_name][$language] as $key => $field) {
    if (is_numeric($key)) {

      // we have to add some extra js for single value fields so we add a class to let the
      // js know
      $extra = $form[$field_name][$language]['#cardinality'] == 1 ? 'single-value' : '';
      $form[$field_name][$language][$key]["add_nodeconnect__{$field_name}_{$key}"] = array(
        '#type' => 'submit',
        '#limit_validation_errors' => array(
          array(
            $field_name,
          ),
        ),
        '#value' => t('Add New @field_title content', array(
          '@field_title' => $form[$field_name][$language]['#title'],
        )),
        '#name' => "add_nodeconnect__{$field_name}_{$key}",
        '#prefix' => "<div class = 'nodeconnect-add {$extra}'>",
        '#suffix' => '</div>',
        '#key' => $key,
        '#field' => $field_name,
        '#add_child' => TRUE,
        '#language' => $language,
        '#submit' => array(
          'nodeconnect_include_form',
          'nodeconnect_add_edit_button_submit',
        ),
        '#weight' => -2,
        '#attached' => array(
          'js' => array(
            drupal_get_path('module', 'nodeconnect') . "/nodeconnect.js",
          ),
          'css' => array(
            drupal_get_path('module', 'nodeconnect') . "/nodeconnect.css",
          ),
        ),
      );
      $form[$field_name][$language][$key]["edit_nodeconnect__{$field_name}_{$key}"] = array(
        '#type' => 'submit',
        '#limit_validation_errors' => array(
          array(
            $field_name,
          ),
        ),
        '#value' => t('Edit referenced @field_title', array(
          '@field_title' => $form[$field_name][$language]['#title'],
        )),
        '#name' => "edit_nodeconnect__{$field_name}_{$key}",
        '#prefix' => "<div class = 'nodeconnect-edit {$extra}'>",
        '#suffix' => '</div>',
        '#key' => $key,
        '#field' => $field_name,
        '#add_child' => FALSE,
        '#language' => 'und',
        '#submit' => array(
          'nodeconnect_include_form',
          'nodeconnect_add_edit_button_submit',
        ),
        '#weight' => -2,
      );
    }
  }
}