You are here

function _ds_field_ui_fields in Display Suite 7

Same name and namespace in other branches
  1. 8.4 includes/field_ui.inc \_ds_field_ui_fields()
  2. 8.2 includes/field_ui.inc \_ds_field_ui_fields()
  3. 8.3 includes/field_ui.inc \_ds_field_ui_fields()
  4. 7.2 includes/ds.field_ui.inc \_ds_field_ui_fields()

Add the fields to the Field UI form.

Parameters

$entity_type: The name of the entity type.

$bundle: The name of the bundle

$view_mode: The name of the view_mode

$form: A collection of form properties.

$form_state: A collection of form_state properties.

1 call to _ds_field_ui_fields()
ds_field_ui_fields_layouts in ./ds.field_ui.inc
Adds the Display Suite fields and layouts to the form.

File

./ds.field_ui.inc, line 1478
Field UI functions for Display Suite.

Code

function _ds_field_ui_fields($entity_type, $bundle, $view_mode, &$form, &$form_state) {

  // Do not add the fields if there is no layout.
  if (!isset($form['#ds_layout'])) {
    return;
  }

  // Get the fields and put them on the form.
  $fields = ds_get_fields($entity_type, FALSE);

  // Ultimate alter on Field UI fields, only used for edge cases.
  $context = array(
    'entity_type' => $entity_type,
    'bundle' => $bundle,
    'view_mode' => $view_mode,
  );

  // Load views file if entity type is not ds_views.
  // We need to cache the hook it's implementing.
  if ($entity_type != 'ds_views' && module_exists('ds_extras') && variable_get('ds_extras_vd', FALSE)) {
    module_load_include('inc', 'ds_extras', 'ds_extras.vd');
  }
  drupal_alter('ds_fields_ui', $fields, $context);

  // Get field settings.
  $field_settings = ds_get_field_settings($entity_type, $bundle, $view_mode, FALSE);
  $form['#field_settings'] = $field_settings;
  $table =& $form['fields'];
  $form['#ds_fields'] = array();
  $field_label_options = array(
    'above' => t('Above'),
    'inline' => t('Inline'),
    'hidden' => t('<Hidden>'),
  );
  drupal_alter('ds_label_options', $field_label_options);
  foreach ($fields as $key => $field) {

    // Check on ui_limit.
    if (isset($field['ui_limit'])) {
      $continue = TRUE;
      foreach ($field['ui_limit'] as $limitation) {
        list($limit_bundle, $limit_view_mode) = explode('|', $limitation);
        if ($limit_bundle == '*' || $limit_bundle == $bundle) {
          if ($limit_view_mode == '*' || $limit_view_mode == $view_mode) {
            $continue = FALSE;
          }
        }
      }
      if ($continue) {
        continue;
      }
    }
    $form['#ds_fields'][] = $key;

    // Check on formatter settings.
    if (isset($form_state['formatter_settings'][$key])) {
      $field['formatter_settings'] = $form_state['formatter_settings'][$key];
    }
    elseif (isset($field_settings[$key]['formatter_settings'])) {
      $field['formatter_settings'] = $field_settings[$key]['formatter_settings'];
      $form_state['formatter_settings'][$key] = $field['formatter_settings'];
    }
    $hidden = array(
      'hidden' => t('<Hidden>'),
    );
    $formatters = isset($field['properties']['formatters']) ? $hidden + $field['properties']['formatters'] : $hidden + array(
      'default' => t('Default'),
    );
    $table[$key] = array(
      '#row_type' => 'field',
      '#js_settings' => array(
        'field',
      ),
      '#region_callback' => 'field_ui_display_overview_row_region',
      '#attributes' => array(
        'class' => array(
          'draggable',
          'tabledrag-leaf',
        ),
      ),
      'human_name' => array(
        '#markup' => check_plain($field['title']),
      ),
      'weight' => array(
        '#type' => 'textfield',
        '#default_value' => isset($field_settings[$key]['weight']) ? $field_settings[$key]['weight'] : 0,
        '#size' => 3,
        '#attributes' => array(
          'class' => array(
            'field-weight',
          ),
        ),
      ),
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
          '#empty_value' => '',
          '#options' => array(),
          '#attributes' => array(
            'class' => array(
              'field-parent',
            ),
          ),
          '#parents' => array(
            'fields',
            $key,
            'parent',
          ),
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $key,
          '#attributes' => array(
            'class' => array(
              'field-name',
            ),
          ),
        ),
      ),
      'label' => array(
        '#type' => 'select',
        '#options' => $field_label_options,
        '#default_value' => isset($field_settings[$key]['label']) ? $field_settings[$key]['label'] : 'hidden',
      ),
      'format' => array(
        'type' => array(
          '#type' => 'select',
          '#options' => $formatters,
          '#default_value' => isset($field_settings[$key]['format']) ? $field_settings[$key]['format'] : 'hidden',
          '#attributes' => array(
            'class' => array(
              'field-formatter-type',
            ),
          ),
        ),
      ),
      'settings_summary' => array(),
      'settings_edit' => array(),
    );

    // Not all fields have settings.
    if (!isset($field['properties']['settings'])) {
      continue;
    }
    $base_button = array(
      '#submit' => array(
        'field_ui_display_overview_multistep_submit',
      ),
      '#ajax' => array(
        'callback' => 'field_ui_display_overview_multistep_js',
        'wrapper' => 'field-display-overview-wrapper',
        'effect' => 'fade',
      ),
      '#field_name' => $key,
    );
    if ($form_state['formatter_settings_edit'] == $key) {
      $field['name'] = $key;
      $field['entity_type'] = $entity_type;
      $field['bundle'] = $bundle;
      $field['view_mode'] = $view_mode;
      $table[$key]['settings_edit'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'class' => array(
            'field-formatter-settings-edit-form',
          ),
        ),
        '#parents' => array(
          'fields',
          $key,
          'settings_edit_form',
        ),
        '#weight' => -5,
        'label' => array(
          '#markup' => '<h3>' . t('Field settings') . '</h3>',
        ),
        // Create a settings form where hooks can pick in.
        'settings' => ds_field_settings_form($field),
        'actions' => array(
          '#type' => 'actions',
          'save_settings' => $base_button + array(
            '#type' => 'submit',
            '#name' => $key . '_formatter_settings_update',
            '#value' => t('Update'),
            '#op' => 'update',
          ),
          'cancel_settings' => $base_button + array(
            '#type' => 'submit',
            '#name' => $key . '_formatter_settings_cancel',
            '#value' => t('Cancel'),
            '#op' => 'cancel',
            // Do not check errors for the 'Cancel' button.
            '#limit_validation_errors' => array(),
          ),
        ),
      );
      $table[$key]['#attributes']['class'][] = 'field-formatter-settings-editing';
      $table[$key]['format']['type']['#attributes']['class'] = array(
        'element-invisible',
      );
    }
    else {

      // After saving, the settings are updated here aswell. First we create
      // the element for the table cell.
      $table[$key]['settings_summary'] = ds_field_settings_summary($field);

      // Add the configure button.
      $table[$key]['settings_edit'] = $base_button + array(
        '#type' => 'image_button',
        '#name' => $key . '_group_settings_edit',
        '#src' => 'misc/configure.png',
        '#attributes' => array(
          'class' => array(
            'field-formatter-settings-edit',
          ),
          'alt' => t('Edit'),
        ),
        '#op' => 'edit',
        // Do not check errors for the 'Edit' button.
        '#limit_validation_errors' => array(),
        '#prefix' => '<div class="field-formatter-settings-edit-wrapper">',
        '#suffix' => '</div>',
      );
    }
  }

  // Add fields submit handler.
  $form['#submit'][] = 'ds_field_ui_fields_save';
}