You are here

function editablefields_field_formatter_settings_form in Editable Fields 7

Implements hook_field_formatter_settings_form().

File

./editablefields.module, line 68
Editable fields module.

Code

function editablefields_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = editablefields_field_formatter_default_settings($display['settings'], $field);

  // Include the field_ui admin form.
  module_load_include('inc', 'field_ui', 'field_ui.admin');

  // Get the list of formatters for this field type, and remove our own.
  $formatters = field_ui_formatter_options($field['type']);
  unset($formatters['editable']);
  $element['click_to_edit'] = array(
    '#type' => 'checkbox',
    '#title' => t('Click to edit'),
    '#default_value' => $settings['click_to_edit'],
  );
  $element['click_to_edit_style'] = array(
    '#type' => 'select',
    '#title' => t('Click to edit style'),
    '#options' => array(
      'button' => t('Button'),
      'hover' => t('Hover'),
    ),
    '#default_value' => $settings['click_to_edit_style'],
  );
  $element['empty_text'] = array(
    '#type' => 'textarea',
    '#rows' => 3,
    '#title' => t('Empty text'),
    '#description' => t('Text to show when the field is empty.'),
    '#default_value' => $settings['empty_text'],
  );
  $element['fallback_format'] = array(
    '#type' => 'select',
    '#title' => t('Fallback formatter'),
    '#options' => $formatters,
    '#default_value' => $settings['fallback_format'],
  );

  // Refresh the form automatically when we know which context we are in.
  if (isset($form_state['complete form']) && $form_state['complete form']['#form_id'] == 'field_ui_display_overview_form') {

    // Field UI.
    $element['fallback_format'] += array(
      '#field_name' => $field['field_name'],
      '#op' => 'edit',
      '#executes_submit_callback' => TRUE,
      '#submit' => array(
        'editablefields_field_ui_display_overview_multistep_submit',
      ),
      '#ajax' => array(
        'callback' => 'field_ui_display_overview_multistep_js',
        'wrapper' => 'field-display-overview-wrapper',
        'effect' => 'fade',
      ),
    );
    $field_name = $form_state['triggering_element']['#field_name'];
    $element['click_to_edit_style'] += array(
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field_name . '][settings_edit_form][settings][click_to_edit]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  else {
    if (isset($form_state['form_id']) && $form_state['form_id'] == 'views_ui_config_item_form') {

      // Views UI.
      $element['fallback_format'] += array(
        '#ajax' => array(
          'path' => views_ui_build_form_url($form_state),
        ),
        '#submit' => array(
          'views_ui_config_item_form_submit_temporary',
        ),
        '#executes_submit_callback' => TRUE,
      );
      $element['click_to_edit_style'] += array(
        '#dependency' => array(
          'edit-options-settings-click-to-edit' => array(
            1,
          ),
        ),
      );
    }
  }
  $fallback_formatter = field_info_formatter_types($settings['fallback_format']);
  $fallback_settings = $settings['fallback_settings'] + field_info_formatter_settings($settings['fallback_format']);

  // Store the settings in a '_dummy' view mode.
  $instance['display']['_dummy'] = array(
    'type' => $settings['fallback_format'],
    'settings' => $fallback_settings,
  );

  // Get the settings form.
  $settings_form = array(
    '#value' => array(),
  );
  $function = $fallback_formatter['module'] . '_field_formatter_settings_form';
  if (function_exists($function)) {
    $settings_form = $function($field, $instance, '_dummy', $form, $form_state);
  }
  $element['fallback_settings'] = $settings_form;
  return $element;
}