You are here

function enterprise_base_form_alter in Enterprise Base 7

Same name and namespace in other branches
  1. 7.3 enterprise_base.module \enterprise_base_form_alter()

Implement hook_form_alter

_state _id

Parameters

unknown_type $form:

File

./enterprise_base.module, line 349

Code

function enterprise_base_form_alter(&$form, &$form_state, $form_id) {

  //dsm(LANGUAGE_NONE);
  if ($form_id == 'field_ui_field_edit_form') {
    $options = array(
      '' => t('Standard'),
      'sidebar' => t('Sidebar'),
    );
    $field_name = $form['#field']['field_name'];

    //dsm($form_state);
    $default = '';
    if (isset($form_state['build_info']['args'][0]['enterprise_edit_form_display'])) {
      $default = $form_state['build_info']['args'][0]['enterprise_edit_form_display'];
    }

    //if (isset($form_state['field'][$field_name][LANGUAGE_NONE]['instance']['enterprise_edit_form_display'])) {

    //  $default = $form_state['field'][$field_name][LANGUAGE_NONE]['instance']['enterprise_edit_form_display'];

    //}
    $form['instance']['enterprise_edit_form_display'] = array(
      '#type' => 'radios',
      '#title' => t('Edit form display location'),
      '#description' => t('Select where you want this field to display on the edit form. Sidebar is recommended for meta data.'),
      '#default_value' => $default,
      '#options' => $options,
    );

    //$form['#submit'][] = 'enterprise_base_form_field_ui_field_edit_form_submit';
  }
  elseif (isset($form['#node_edit_form'])) {

    // if admin theme is Rubik, enhance node admin
    $theme = variable_get('admin_theme', 'bartik');
    $node_admin = variable_get('node_admin_theme', 'bartik');
    if ($theme != 'rubik' || !$node_admin) {
      return;
    }
    drupal_add_js(drupal_get_path('module', 'enterprise_base') . '/js/enterprise_base.edit_form.js');
    drupal_add_css(drupal_get_path('module', 'enterprise_base') . '/css/enterprise_base.edit_form.css');
    if (isset($form_state['field']) && is_array($form_state['field'])) {
      foreach ($form_state['field'] as $name => $field) {
        if (!isset($field[LANGUAGE_NONE]['instance'])) {
          continue;
        }
        $field[LANGUAGE_NONE]['instance'] += array(
          'enterprise_edit_form_display' => '',
        );
        $display = $field[LANGUAGE_NONE]['instance']['enterprise_edit_form_display'];
        if ($display == 'sidebar') {
          $form[$name]['#attributes']['class'][] = 'display_sidebar';

          // set field to scrollable if checkboxes or radios
          if (isset($form[$name][LANGUAGE_NONE]['#type']) && in_array($form[$name][LANGUAGE_NONE]['#type'], array(
            'checkboxes',
            'radios',
          ))) {
            $form[$name][LANGUAGE_NONE]['#attributes']['class'][] = 'scrollable';
          }
        }

        // if closed vocabular, add + add term link to field
        $fdata = $form_state['field'][$name][LANGUAGE_NONE];
        if ($fdata['field']['type'] == 'taxonomy_term_reference' && $fdata['instance']['widget']['type'] == 'options_buttons') {
          $vocab_name = $fdata['field']['settings']['allowed_values'][0]['vocabulary'];
          $item = menu_get_item("admin/structure/taxonomy/{$vocab_name}/add");
          if ($item['access']) {
            $form[$name][LANGUAGE_NONE]['#attributes']['class'][] = 'with-action-links';

            // TODO work out styling
            $form[$name][LANGUAGE_NONE]['#field_suffix'] = '<ul class="action-linksx"><li>' . l('+ ' . t('Add @name term', array(
              '@name' => $vocab_name,
            )), "admin/structure/taxonomy/{$vocab_name}/add", array(
              'html' => TRUE,
              'attributes' => array(
                'target' => "_blank",
                'class' => array(
                  'add-term-link',
                ),
              ),
            )) . '</li></ul>';
          }
        }
      }
    }

    // move schedual
    if (isset($form['scheduler_settings'])) {
      unset($form['scheduler_settings']['#group']);
      unset($form['scheduler_settings']['#attached']);
      $form['scheduler_settings']['#title'] = $form['scheduler_settings']['publish_on']['#title'];
      unset($form['scheduler_settings']['publish_on']['#title']);
      $form['scheduler_settings']['#attributes']['class'][] = 'display_sidebar';
      $form['scheduler_settings']['#weight'] = -10;
    }
    if (isset($form['metatags'])) {
      $form['metatags']['#weight'] = -20;
    }
  }

  //dsm($form_id);

  //dsm($form);

  //dsm($form_state);
}