You are here

function linkit_form_field_ui_field_edit_form_alter in Linkit 7.3

Same name and namespace in other branches
  1. 7.2 linkit.field.inc \linkit_form_field_ui_field_edit_form_alter()

Implements hook_form_FIELD_UI_FIELD_EDIT_FORM_alter().

File

./linkit.field.inc, line 103
Implementation for Fields and Linkit.

Code

function linkit_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  $instance = $form['#instance'];
  if (isset($form['locked']) && $form['locked']) {
    return;
  }

  // Get allowed field types.
  $allowed_field_types = linkit_get_allowed_field_types();

  // Get allowed field widget types.
  $allowed_field_widget_types = linkit_get_allowed_field_widget_types();
  $allowed_field = in_array($form['#field']['type'], $allowed_field_types);
  $allowed_widget = in_array($form['instance']['widget']['type']['#value'], $allowed_field_widget_types);

  // Add the linkit settings to the field instance form if it's valid.
  if ($allowed_field && $allowed_widget) {

    // Fieldset for Linkit settings on this field instance.
    $form['instance']['settings']['linkit'] = array(
      '#type' => 'fieldset',
      '#title' => t('Linkit field settings'),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );

    // Enable Linkit on this field instance.
    $form['instance']['settings']['linkit']['enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable Linkit for this field.'),
      '#default_value' => isset($instance['settings']['linkit']['enable']) ? $instance['settings']['linkit']['enable'] : 0,
      '#description' => t('Do not use this for CKeditor and TinyMCE fields. You will have to configure this on the wysiwyg/ckeditor profile.'),
    );
    $profiles = linkit_profile_field_load_all();
    $options = array();
    foreach ($profiles as $profile) {
      $options[$profile->name] = $profile->admin_title;
    }

    // Sort the options.
    natsort($options);
    $form['instance']['settings']['linkit']['profile'] = array(
      '#type' => 'select',
      '#title' => t('Profile'),
      '#options' => $options,
      '#empty_option' => t('- Select a profile -'),
      '#default_value' => isset($instance['settings']['linkit']['profile']) ? $instance['settings']['linkit']['profile'] : '',
      '#states' => array(
        'invisible' => array(
          'input[name="instance[settings][linkit][enable]"]' => array(
            'checked' => FALSE,
          ),
        ),
        'required' => array(
          'input[name="instance[settings][linkit][enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#element_validate' => array(
        'linkit_field_profile_validate',
      ),
    );

    // Enable Linkit on this field instance.
    $form['instance']['settings']['linkit']['button_text'] = array(
      '#type' => 'textfield',
      '#title' => t('Button text that activates linkit modal.'),
      '#default_value' => isset($instance['settings']['linkit']['button_text']) ? $instance['settings']['linkit']['button_text'] : t('Search'),
    );
  }
}