field_ui.admin.inc 74.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
// $Id$

/**
 * @file
 * Administrative interface for custom field type creation.
 */

/**
 * Menu callback; lists all defined fields for quick reference.
 */
function field_ui_fields_list() {
  $instances = field_info_instances();
  $field_types = field_info_field_types();
  $bundles = field_info_bundles();
  $header = array(t('Field name'), t('Field type'), t('Used in'));
  $rows = array();
18
  foreach ($instances as $entity_type => $type_bundles) {
19 20
    foreach ($type_bundles as $bundle => $bundle_instances) {
      foreach ($bundle_instances as $field_name => $instance) {
21
        $field = field_info_field($field_name);
22
        $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
23 24
        $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;
        $rows[$field_name]['data'][1] = t($field_types[$field['type']]['label']);
25
        $rows[$field_name]['data'][2][] = l($bundles[$entity_type][$bundle]['label'], $admin_path . '/fields');
26 27
        $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');
      }
28 29 30 31 32 33
    }
  }
  foreach ($rows as $field_name => $cell) {
    $rows[$field_name]['data'][2] = implode(', ', $cell['data'][2]);
  }
  if (empty($rows)) {
34
    $output = t('No fields have been defined yet.');
35 36 37 38
  }
  else {
    // Sort rows by field name.
    ksort($rows);
39
    $output = theme('table', array('header' => $header, 'rows' => $rows));
40 41 42 43 44 45 46
  }
  return $output;
}

/**
 * Helper function to display a message about inactive fields.
 */
47 48
function field_ui_inactive_message($entity_type, $bundle) {
  $inactive_instances = field_ui_inactive_instances($entity_type, $bundle);
49 50 51 52 53 54 55 56 57 58 59 60
  if (!empty($inactive_instances)) {
    $field_types = field_info_field_types();
    $widget_types = field_info_widget_types();

    foreach ($inactive_instances as $field_name => $instance) {
      $list[] = t('%field (@field_name) field requires the %widget_type widget provided by %widget_module module', array(
      '%field' => $instance['label'],
      '@field_name' => $instance['field_name'],
      '%widget_type' => array_key_exists($instance['widget']['type'], $widget_types) ? $widget_types[$instance['widget']['type']]['label'] : $instance['widget']['type'],
      '%widget_module' => $instance['widget']['module'],
      ));
    }
61
    drupal_set_message(t('Inactive fields are not shown unless their providing modules are enabled. The following fields are not enabled: !list', array('!list' => theme('item_list', array('items' => $list)))), 'error');
62 63 64
  }
}

65 66 67 68 69 70
/**
 * Helper function: determines the rendering order of a tree array.
 *
 * This is intended as a callback for array_reduce().
 */
function _field_ui_reduce_order($array, $a) {
71
  $array = !isset($array) ? array() : $array;
72 73 74 75 76 77 78 79 80 81 82
  if ($a['name']) {
    $array[] = $a['name'];
  }
  if (!empty($a['children'])) {
    uasort($a['children'], 'drupal_sort_weight');
    $array = array_merge($array, array_reduce($a['children'], '_field_ui_reduce_order'));
  }
  return $array;
}

/**
83
 * Returns the region to which a row in the 'Manage fields' screen belongs.
84
 *
85 86
 * This function is used as a #row_callback in field_ui_field_overview_form(),
 * and is called during field_ui_table_pre_render().
87
 */
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
function field_ui_field_overview_row_region($row) {
  switch ($row['#row_type']) {
    case 'field':
    case 'extra_field':
      return 'main';
    case 'add_new_field':
      // If no input in 'label', assume the row has not been dragged out of the
      // 'add new' section.
      return (!empty($row['label']['#value']) ? 'main' : 'add_new');
  }
}

/**
 * Returns the region to which a row in the 'Manage display' screen belongs.
 *
 * This function is used as a #row_callback in field_ui_field_overview_form(),
 * and is called during field_ui_table_pre_render().
 */
function field_ui_display_overview_row_region($row) {
  switch ($row['#row_type']) {
    case 'field':
    case 'extra_field':
      return ($row['format']['type']['#value'] == 'hidden' ? 'hidden' : 'visible');
  }
}

/**
 * Pre-render callback for field_ui_table elements.
 */
function field_ui_table_pre_render($elements) {
  $js_settings = array();
119

120 121 122 123
  // For each region, build the tree structure from the weight and parenting
  // data contained in the flat form structure, to determine row order and
  // indentation.
  $regions = $elements['#regions'];
124
  $tree = array('' => array('name' => '', 'children' => array()));
125 126
  $trees = array_fill_keys(array_keys($regions), $tree);

127 128
  $parents = array();
  $list = drupal_map_assoc(element_children($elements));
129

130 131 132 133 134 135 136
  // Iterate on rows until we can build a known tree path for all of them.
  while ($list) {
    foreach ($list as $name) {
      $row = &$elements[$name];
      $parent = $row['parent_wrapper']['parent']['#value'];
      // Proceed if parent is known.
      if (empty($parent) || isset($parents[$parent])) {
137
        // Grab parent, and remove the row from the next iteration.
138 139 140
        $parents[$name] = $parent ? array_merge($parents[$parent], array($parent)) : array();
        unset($list[$name]);

141 142 143 144
        // Determine the region for the row.
        $function = $row['#region_callback'];
        $region_name = $function($row);

145
        // Add the element in the tree.
146
        $target = &$trees[$region_name][''];
147 148 149 150 151 152 153 154 155 156
        foreach ($parents[$name] as $key) {
          $target = &$target['children'][$key];
        }
        $target['children'][$name] = array('name' => $name, 'weight' => $row['weight']['#value']);

        // Add tabledrag indentation to the first row cell.
        if ($depth = count($parents[$name])) {
          $cell = current(element_children($row));
          $row[$cell]['#prefix'] = theme('indentation', array('size' => $depth)) . (isset($row[$cell]['#prefix']) ? $row[$cell]['#prefix'] : '');
        }
157 158 159 160 161 162 163 164 165 166 167 168 169

        // Add row id and associate JS settings.
        $id = drupal_html_class($name);
        $row['#attributes']['id'] = $id;
        $row += array(
          '#js_settings' => array(),
        );
        $row['#js_settings'] += array(
          'rowHandler' => $row['#row_type'],
          'name' => $name,
          'region' => $region_name,
        );
        $js_settings[$id] = $row['#js_settings'];
170 171 172
      }
    }
  }
173 174 175 176
  // Determine rendering order from the tree structure.
  foreach ($regions as $region_name => $region) {
    $elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], '_field_ui_reduce_order');
  }
177

178 179 180 181
  $elements['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array('fieldUIRowsData' => $js_settings),
  );
182 183

  return $elements;
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
}

/**
 * Returns HTML for Field UI overview tables.
 *
 * @param $variables
 *   An associative array containing:
 *   - elements: An associative array containing a Form API structure to be
 *     rendered as a table.
 *
 * @ingroup themeable
 */
function theme_field_ui_table($variables) {
  $elements = $variables['elements'];
  $table = array();
199
  $js_settings = array();
200

201
  // Add table headers and attributes.
202 203 204 205 206 207
  foreach (array('header', 'attributes') as $key) {
    if (isset($elements["#$key"])) {
      $table[$key] = $elements["#$key"];
    }
  }

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  // Determine the colspan to use for region rows, by checking the number of
  // columns in the headers.
  $colums_count = 0;
  foreach ($table['header'] as $header) {
    $colums_count += (is_array($header) && isset($header['colspan']) ? $header['colspan'] : 1);
  }

  // Render rows, region by region.
  foreach ($elements['#regions'] as $region_name => $region) {
    $region_name_class = drupal_html_class($region_name);

    // Add region rows.
    if (isset($region['title'])) {
      $table['rows'][] = array(
        'class' => array('region-title', 'region-' . $region_name_class . '-title'),
        'no_striping' => TRUE,
        'data' => array(
          array('data' => $region['title'], 'colspan' => $colums_count),
        ),
      );
    }
    if (isset($region['message'])) {
      $class = (empty($region['rows_order']) ? 'region-empty' : 'region-populated');
      $table['rows'][] = array(
        'class' => array('region-message', 'region-' . $region_name_class . '-message', $class),
        'no_striping' => TRUE,
        'data' => array(
          array('data' => $region['message'], 'colspan' => $colums_count),
        ),
      );
    }

    // Add form rows, in the order determined at pre-render time.
    foreach ($region['rows_order'] as $name) {
      $element = $elements[$name];

      $row = array('data' => array());
      if (isset($element['#attributes'])) {
        $row += $element['#attributes'];
      }
248

249 250 251 252 253 254
      foreach (element_children($element) as $cell_key) {
        $cell = array('data' => drupal_render($element[$cell_key]));
        if (isset($element[$cell_key]['#cell_attributes'])) {
          $cell += $element[$cell_key]['#cell_attributes'];
        }
        $row['data'][] = $cell;
255
      }
256
      $table['rows'][] = $row;
257 258 259 260 261 262
    }
  }

  return theme('table', $table);
}

263
/**
264
 * Menu callback; listing of fields for a bundle.
265 266 267
 *
 * Allows fields and pseudo-fields to be re-ordered.
 */
268 269
function field_ui_field_overview_form($form, &$form_state, $entity_type, $bundle) {
  $bundle = field_extract_bundle($entity_type, $bundle);
270

271 272
  field_ui_inactive_message($entity_type, $bundle);
  $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
273 274 275

  // When displaying the form, make sure the list of fields is up-to-date.
  if (empty($form_state['post'])) {
276
    field_info_cache_clear();
277 278 279
  }

  // Gather bundle information.
280
  $instances = field_info_instances($entity_type, $bundle);
281 282 283
  $field_types = field_info_field_types();
  $widget_types = field_info_widget_types();

284
  $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');
285

286
  $form += array(
287
    '#entity_type' => $entity_type,
288 289
    '#bundle' => $bundle,
    '#fields' => array_keys($instances),
290
    '#extra' => array_keys($extra_fields),
291 292
  );

293
  $table = array(
294
    '#type' => 'field_ui_table',
295 296 297 298 299 300 301 302 303 304
    '#tree' => TRUE,
    '#header' => array(
      t('Label'),
      t('Weight'),
      t('Parent'),
      t('Name'),
      t('Field'),
      t('Widget'),
      array('data' => t('Operations'), 'colspan' => 2),
    ),
305
    '#parent_options' => array(),
306 307 308 309 310 311 312 313
    '#regions' => array(
      'main' => array(),
      'add_new' => array('title' => '&nbsp;'),
    ),
    '#attributes' => array(
      'class' => array('field-ui-overview'),
      'id' => 'field-overview',
    ),
314 315
  );

316 317 318 319
  // Fields.
  foreach ($instances as $name => $instance) {
    $field = field_info_field($instance['field_name']);
    $admin_field_path = $admin_path . '/fields/' . $instance['field_name'];
320
    $table[$name] = array(
321 322 323
      '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
      '#row_type' => 'field',
      '#region_callback' => 'field_ui_field_overview_row_region',
324 325 326
      'label' => array(
        '#markup' => check_plain($instance['label']),
      ),
327 328
      'weight' => array(
        '#type' => 'textfield',
329 330
        '#title' => t('Weight for @title', array('@title' => $instance['label'])),
        '#title_display' => 'invisible',
331
        '#default_value' => $instance['widget']['weight'],
332 333 334 335 336 337
        '#size' => 3,
        '#attributes' => array('class' => array('field-weight')),
       ),
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
338 339
          '#title' => t('Parent for @title', array('@title' => $instance['label'])),
          '#title_display' => 'invisible',
340
          '#options' => $table['#parent_options'],
341
          '#empty_value' => '',
342
          '#attributes' => array('class' => array('field-parent')),
343
          '#parents' => array('fields', $name, 'parent'),
344 345 346 347 348 349 350
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $name,
          '#attributes' => array('class' => array('field-name')),
        ),
      ),
351 352 353 354
      'field_name' => array(
        '#markup' => $instance['field_name'],
      ),
      'type' => array(
355 356 357 358
        '#type' => 'link',
        '#title' => t($field_types[$field['type']]['label']),
        '#href' => $admin_field_path . '/field-settings',
        '#options' => array('attributes' => array('title' => t('Edit field settings.'))),
359 360
      ),
      'widget_type' => array(
361 362 363 364
        '#type' => 'link',
        '#title' => t($widget_types[$instance['widget']['type']]['label']),
        '#href' => $admin_field_path . '/widget-type',
        '#options' => array('attributes' => array('title' => t('Change widget type.'))),
365 366
      ),
      'edit' => array(
367 368 369 370
        '#type' => 'link',
        '#title' => t('edit'),
        '#href' => $admin_field_path,
        '#options' => array('attributes' => array('title' => t('Edit instance settings.'))),
371 372
      ),
      'delete' => array(
373 374 375 376 377
        '#type' => 'link',
        '#title' => t('delete'),
        '#href' => $admin_field_path . '/delete',
        '#options' => array('attributes' => array('title' => t('Delete instance.'))),
      ),
378 379 380
    );

    if (!empty($instance['locked'])) {
381 382 383
      $table[$name]['edit'] = array('#value' => t('Locked'));
      $table[$name]['delete'] = array();
      $table[$name]['#attributes']['class'][] = 'menu-disabled';
384 385 386 387
    }
  }

  // Non-field elements.
388
  foreach ($extra_fields as $name => $extra_field) {
389
    $table[$name] = array(
390 391 392
      '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
      '#row_type' => 'extra_field',
      '#region_callback' => 'field_ui_field_overview_row_region',
393
      'label' => array(
394
        '#markup' => check_plain($extra_field['label']),
395 396 397
      ),
      'weight' => array(
        '#type' => 'textfield',
398
        '#default_value' => $extra_field['weight'],
399
        '#size' => 3,
400
        '#attributes' => array('class' => array('field-weight')),
401
        '#title_display' => 'invisible',
402
        '#title' => t('Weight for @title', array('@title' => $extra_field['label'])),
403
      ),
404 405 406
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
407 408
          '#title' => t('Parent for @title', array('@title' => $extra_field['label'])),
          '#title_display' => 'invisible',
409
          '#options' => $table['#parent_options'],
410
          '#empty_value' => '',
411
          '#attributes' => array('class' => array('field-parent')),
412
          '#parents' => array('fields', $name, 'parent'),
413 414 415 416 417 418 419 420 421 422 423 424 425 426
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $name,
          '#attributes' => array('class' => array('field-name')),
        ),
      ),
      'field_name' => array(
        '#markup' => $name,
      ),
      'type' => array(
        '#markup' => isset($extra_field['description']) ? $extra_field['description'] : '',
        '#cell_attributes' => array('colspan' => 2),
      ),
427
      'edit' => array(
428
        '#markup' => isset($extra_field['edit']) ? $extra_field['edit'] : '',
429 430
      ),
      'delete' => array(
431
        '#markup' => isset($extra_field['delete']) ? $extra_field['delete'] : '',
432 433 434 435 436
      ),
    );
  }

  // Additional row: add new field.
437
  $max_weight = field_info_max_weight($entity_type, $bundle, 'form');
438 439 440 441
  $field_type_options = field_ui_field_type_options();
  $widget_type_options = field_ui_widget_type_options(NULL, TRUE);
  if ($field_type_options && $widget_type_options) {
    $name = '_add_new_field';
442 443
    $table[$name] = array(
      '#attributes' => array('class' => array('draggable', 'tabledrag-leaf', 'add-new')),
444 445
      '#row_type' => 'add_new_field',
      '#region_callback' => 'field_ui_field_overview_row_region',
446 447
      'label' => array(
        '#type' => 'textfield',
448 449
        '#title' => t('New field label'),
        '#title_display' => 'invisible',
450 451
        '#size' => 15,
        '#description' => t('Label'),
452 453 454 455 456
        '#prefix' => '<div class="label-input"><div class="add-new-placeholder">' . t('Add new field') .'</div>',
        '#suffix' => '</div>',
      ),
      'weight' => array(
        '#type' => 'textfield',
457
        '#default_value' => $max_weight + 1,
458 459 460 461 462 463 464 465 466
        '#size' => 3,
        '#title_display' => 'invisible',
        '#title' => t('Weight for new field'),
        '#attributes' => array('class' => array('field-weight')),
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
      ),
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
467 468
          '#title' => t('Parent for new field'),
          '#title_display' => 'invisible',
469
          '#options' => $table['#parent_options'],
470
          '#empty_value' => '',
471 472
          '#attributes' => array('class' => array('field-parent')),
          '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
473
          '#parents' => array('fields', $name, 'parent'),
474 475 476 477 478 479
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $name,
          '#attributes' => array('class' => array('field-name')),
        ),
480 481 482
      ),
      'field_name' => array(
        '#type' => 'textfield',
483 484
        '#title' => t('New field name'),
        '#title_display' => 'invisible',
485 486 487 488
        // This field should stay LTR even for RTL languages.
        '#field_prefix' => '<span dir="ltr">field_',
        '#field_suffix' => '</span>&lrm;',
        '#attributes' => array('dir'=>'ltr'),
489
        '#size' => 10,
490
        '#description' => t('Field name (a-z, 0-9, _)'),
491
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
492 493 494
      ),
      'type' => array(
        '#type' => 'select',
495 496
        '#title' => t('Type of new field'),
        '#title_display' => 'invisible',
497
        '#options' => $field_type_options,
498
        '#empty_option' => t('- Select a field type -'),
499
        '#description' => t('Type of data to store.'),
500 501
        '#attributes' => array('class' => array('field-type-select')),
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
502 503 504
      ),
      'widget_type' => array(
        '#type' => 'select',
505 506
        '#title' => t('Widget for new field'),
        '#title_display' => 'invisible',
507
        '#options' => $widget_type_options,
508
        '#empty_option' => t('- Select a widget -'),
509
        '#description' => t('Form element to edit the data.'),
510 511 512
        '#attributes' => array('class' => array('widget-type-select')),
        '#cell_attributes' => array('colspan' => 3),
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
513 514 515 516 517
      ),
    );
  }

  // Additional row: add existing field.
518
  $existing_field_options = field_ui_existing_field_options($entity_type, $bundle);
519 520
  if ($existing_field_options && $widget_type_options) {
    $name = '_add_existing_field';
521
    $table[$name] = array(
522
      '#attributes' => array('class' => array('draggable', 'tabledrag-leaf', 'add-new')),
523 524
      '#row_type' => 'add_new_field',
      '#region_callback' => 'field_ui_field_overview_row_region',
525 526
      'label' => array(
        '#type' => 'textfield',
527 528
        '#title' => t('Existing field label'),
        '#title_display' => 'invisible',
529 530
        '#size' => 15,
        '#description' => t('Label'),
531 532 533 534 535 536
        '#attributes' => array('class' => array('label-textfield')),
        '#prefix' => '<div class="label-input"><div class="add-new-placeholder">' . t('Add existing field') .'</div>',
        '#suffix' => '</div>',
      ),
      'weight' => array(
        '#type' => 'textfield',
537
        '#default_value' => $max_weight + 2,
538 539 540 541 542 543 544 545 546
        '#size' => 3,
        '#title_display' => 'invisible',
        '#title' => t('Weight for added field'),
        '#attributes' => array('class' => array('field-weight')),
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
      ),
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
547 548
          '#title' => t('Parent for existing field'),
          '#title_display' => 'invisible',
549
          '#options' => $table['#parent_options'],
550
          '#empty_value' => '',
551 552
          '#attributes' => array('class' => array('field-parent')),
          '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
553
          '#parents' => array('fields', $name, 'parent'),
554 555 556 557 558 559
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $name,
          '#attributes' => array('class' => array('field-name')),
        ),
560 561 562
      ),
      'field_name' => array(
        '#type' => 'select',
563 564
        '#title' => t('Existing field to share'),
        '#title_display' => 'invisible',
565
        '#options' => $existing_field_options,
566
        '#empty_option' => t('- Select an existing field -'),
567
        '#description' => t('Field to share'),
568 569 570
        '#attributes' => array('class' => array('field-select')),
        '#cell_attributes' => array('colspan' => 2),
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
571 572 573
      ),
      'widget_type' => array(
        '#type' => 'select',
574 575
        '#title' => t('Widget for existing field'),
        '#title_display' => 'invisible',
576
        '#options' => $widget_type_options,
577
        '#empty_option' => t('- Select a widget -'),
578
        '#description' => t('Form element to edit the data.'),
579 580 581
        '#attributes' => array('class' => array('widget-type-select')),
        '#cell_attributes' => array('colspan' => 3),
        '#prefix' => '<div class="add-new-placeholder">&nbsp;</div>',
582 583 584
      ),
    );
  }
585
  $form['fields'] = $table;
586

587 588
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
589

590 591
  $form['#attached']['css'][] = drupal_get_path('module', 'field_ui') . '/field_ui.css';
  $form['#attached']['js'][] = drupal_get_path('module', 'field_ui') . '/field_ui.js';
592

593 594
  // Add settings for the update selects behavior.
  $js_fields = array();
595
  foreach ($existing_field_options as $field_name => $fields) {
596
    $field = field_info_field($field_name);
597
    $instance = field_info_instance($form['#entity_type'], $field_name, $form['#bundle']);
598 599 600
    $js_fields[$field_name] = array('label' => $instance['label'], 'type' => $field['type'], 'widget' => $instance['widget']['type']);
  }

601 602
  $form['#attached']['js'][] = array(
    'type' => 'setting',
603
    'data' => array('fields' => $js_fields, 'fieldWidgetTypes' => field_ui_widget_type_options()),
604
  );
605

606 607 608 609 610
  // Add tabledrag behavior.
  $form['#attached']['drupal_add_tabledrag'][] = array('field-overview', 'order', 'sibling', 'field-weight');
  $form['#attached']['drupal_add_tabledrag'][] = array('field-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');

  return $form;
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
}

/**
 * Validate handler for the field overview form.
 */
function field_ui_field_overview_form_validate($form, &$form_state) {
  _field_ui_field_overview_form_validate_add_new($form, $form_state);
  _field_ui_field_overview_form_validate_add_existing($form, $form_state);
}

/**
 * Helper function for field_ui_field_overview_form_validate.
 *
 * Validate the 'add new field' row.
 */
function _field_ui_field_overview_form_validate_add_new($form, &$form_state) {
627
  $field = $form_state['values']['fields']['_add_new_field'];
628 629 630 631 632

  // Validate if any information was provided in the 'add new field' row.
  if (array_filter(array($field['label'], $field['field_name'], $field['type'], $field['widget_type']))) {
    // Missing label.
    if (!$field['label']) {
633
      form_set_error('fields][_add_new_field][label', t('Add new field: you need to provide a label.'));
634 635 636 637
    }

    // Missing field name.
    if (!$field['field_name']) {
638
      form_set_error('fields][_add_new_field][field_name', t('Add new field: you need to provide a field name.'));
639 640 641 642 643 644 645 646
    }
    // Field name validation.
    else {
      $field_name = $field['field_name'];

      // Add the 'field_' prefix.
      if (substr($field_name, 0, 6) != 'field_') {
        $field_name = 'field_' . $field_name;
647
        form_set_value($form['fields']['_add_new_field']['field_name'], $field_name, $form_state);
648 649 650 651
      }

      // Invalid field name.
      if (!preg_match('!^field_[a-z0-9_]+$!', $field_name)) {
652
        form_set_error('fields][_add_new_field][field_name', t('Add new field: the field name %field_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%field_name' => $field_name)));
653 654
      }
      if (strlen($field_name) > 32) {
655
        form_set_error('fields][_add_new_field][field_name', t("Add new field: the field name %field_name is too long. The name is limited to 32 characters, including the 'field_' prefix.", array('%field_name' => $field_name)));
656 657 658 659 660 661
      }

      // Field name already exists. We need to check inactive fields as well, so
      // we can't use field_info_fields().
      $fields = field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE));
      if ($fields) {
662
        form_set_error('fields][_add_new_field][field_name', t('Add new field: the field name %field_name already exists.', array('%field_name' => $field_name)));
663 664 665 666 667
      }
    }

    // Missing field type.
    if (!$field['type']) {
668
      form_set_error('fields][_add_new_field][type', t('Add new field: you need to select a field type.'));
669 670 671 672
    }

    // Missing widget type.
    if (!$field['widget_type']) {
673
      form_set_error('fields][_add_new_field][widget_type', t('Add new field: you need to select a widget.'));
674 675 676 677 678
    }
    // Wrong widget type.
    elseif ($field['type']) {
      $widget_types = field_ui_widget_type_options($field['type']);
      if (!isset($widget_types[$field['widget_type']])) {
679
        form_set_error('fields][_add_new_field][widget_type', t('Add new field: invalid widget.'));
680 681 682 683 684 685 686 687 688 689 690 691
      }
    }
  }
}

/**
 * Helper function for field_ui_field_overview_form_validate.
 *
 * Validate the 'add existing field' row.
 */
function _field_ui_field_overview_form_validate_add_existing($form, &$form_state) {
  // The form element might be absent if no existing fields can be added to
692
  // this bundle.
693 694
  if (isset($form_state['values']['fields']['_add_existing_field'])) {
    $field = $form_state['values']['fields']['_add_existing_field'];
695 696 697 698 699

    // Validate if any information was provided in the 'add existing field' row.
    if (array_filter(array($field['label'], $field['field_name'], $field['widget_type']))) {
      // Missing label.
      if (!$field['label']) {
700
        form_set_error('fields][_add_existing_field][label', t('Add existing field: you need to provide a label.'));
701 702 703 704
      }

      // Missing existing field name.
      if (!$field['field_name']) {
705
        form_set_error('fields][_add_existing_field][field_name', t('Add existing field: you need to select a field.'));
706 707 708 709
      }

      // Missing widget type.
      if (!$field['widget_type']) {
710
        form_set_error('fields][_add_existing_field][widget_type', t('Add existing field: you need to select a widget.'));
711 712 713 714 715
      }
      // Wrong widget type.
      elseif ($field['field_name'] && ($existing_field = field_info_field($field['field_name']))) {
        $widget_types = field_ui_widget_type_options($existing_field['type']);
        if (!isset($widget_types[$field['widget_type']])) {
716
          form_set_error('fields][_add_existing_field][widget_type', t('Add existing field: invalid widget.'));
717 718 719 720 721 722 723 724 725 726
        }
      }
    }
  }
}

/**
 * Submit handler for the field overview form.
 */
function field_ui_field_overview_form_submit($form, &$form_state) {
727
  $form_values = $form_state['values']['fields'];
728
  $entity_type = $form['#entity_type'];
729
  $bundle = $form['#bundle'];
730
  $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
731

732 733
  $bundle_settings = field_bundle_settings($entity_type, $bundle);

734 735 736
  // Update field weights.
  foreach ($form_values as $key => $values) {
    if (in_array($key, $form['#fields'])) {
737
      $instance = field_read_instance($entity_type, $key, $bundle);
738 739 740 741
      $instance['widget']['weight'] = $values['weight'];
      field_update_instance($instance);
    }
    elseif (in_array($key, $form['#extra'])) {
742
      $bundle_settings['extra_fields']['form'][$key]['weight'] = $values['weight'];
743 744 745
    }
  }

746
  field_bundle_settings($entity_type, $bundle, $bundle_settings);
747 748 749 750 751 752 753 754 755 756 757

  $destinations = array();

  // Create new field.
  $field = array();
  if (!empty($form_values['_add_new_field']['field_name'])) {
    $values = $form_values['_add_new_field'];

    $field = array(
      'field_name' => $values['field_name'],
      'type' => $values['type'],
758
      'translatable' => TRUE,
759 760 761
    );
    $instance = array(
      'field_name' => $field['field_name'],
762
      'entity_type' => $entity_type,
763 764 765 766 767 768 769 770 771 772 773 774 775 776
      'bundle' => $bundle,
      'label' => $values['label'],
      'widget' => array(
        'type' => $values['widget_type'],
        'weight' => $values['weight'],
      ),
    );

    // Create the field and instance.
    try {
      field_create_field($field);
      field_create_instance($instance);

      $destinations[] = $admin_path . '/fields/' . $field['field_name'] . '/field-settings';
777
      $destinations[] = $admin_path . '/fields/' . $field['field_name'];
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796

      // Store new field information for any additional submit handlers.
      $form_state['fields_added']['_add_new_field'] = $field['field_name'];
    }
    catch (Exception $e) {
      drupal_set_message(t('There was a problem creating field %label: @message.', array('%label' => $instance['label'], '@message' => $e->getMessage())));
    }
  }

  // Add existing field.
  if (!empty($form_values['_add_existing_field']['field_name'])) {
    $values = $form_values['_add_existing_field'];
    $field = field_info_field($values['field_name']);
    if (!empty($field['locked'])) {
      drupal_set_message(t('The field %label cannot be added because it is locked.', array('%label' => $values['label'])));
    }
    else {
      $instance = array(
        'field_name' => $field['field_name'],
797
        'entity_type' => $entity_type,
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
        'bundle' => $bundle,
        'label' => $values['label'],
        'widget' => array(
          'type' => $values['widget_type'],
          'weight' => $values['weight'],
        ),
      );

      try {
        field_create_instance($instance);
        $destinations[] = $admin_path . '/fields/' . $instance['field_name'] . '/edit';
        // Store new field information for any additional submit handlers.
        $form_state['fields_added']['_add_existing_field'] = $instance['field_name'];
      }
      catch (Exception $e) {
        drupal_set_message(t('There was a problem creating field instance %label: @message.', array('%label' => $instance['label'], '@message' => $e->getMessage())));
      }
    }
  }

  if ($destinations) {
819 820
    $destination = drupal_get_destination();
    $destinations[] = $destination['destination'];
821
    unset($_GET['destination']);
822 823
    $form_state['redirect'] = field_ui_get_destinations($destinations);
  }
824 825 826
  else {
    drupal_set_message(t('Your settings have been saved.'));
  }
827 828 829
}

/**
830
 * Menu callback; presents field display settings for a given view mode.
831
 */
832
function field_ui_display_overview_form($form, &$form_state, $entity_type, $bundle, $view_mode) {
833
  $bundle = field_extract_bundle($entity_type, $bundle);
834

835 836
  field_ui_inactive_message($entity_type, $bundle);
  $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
837 838

  // Gather type information.
839
  $instances = field_info_instances($entity_type, $bundle);
840
  $field_types = field_info_field_types();
841
  $extra_fields = field_info_extra_fields($entity_type, $bundle, 'display');
842

843 844 845 846
  $form_state += array(
    'formatter_settings_edit' => NULL,
  );

847
  $form += array(
848
    '#entity_type' => $entity_type,
849
    '#bundle' => $bundle,
850
    '#view_mode' => $view_mode,
851
    '#fields' => array_keys($instances),
852
    '#extra' => array_keys($extra_fields),
853 854 855 856 857 858 859
  );

  if (empty($instances)) {
    drupal_set_message(t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => url($admin_path . '/fields'))), 'warning');
    return $form;
  }

860
  $table = array(
861
    '#type' => 'field_ui_table',
862
    '#tree' => TRUE,
863 864 865 866 867 868 869 870 871 872 873
    '#header' => array(
      t('Field'),
      t('Weight'),
      t('Parent'),
      t('Label'),
      array('data' => t('Format'), 'colspan' => 3),
    ),
    '#regions' => array(
      'visible' => array('message' => t('No field is displayed.')),
      'hidden' => array('title' => t('Hidden'), 'message' => t('No field is hidden.')),
    ),
874
    '#parent_options' => array(),
875 876 877 878 879 880 881
    '#attributes' => array(
      'class' => array('field-ui-overview'),
      'id' => 'field-display-overview',
    ),
    // Add AJAX wrapper.
    '#prefix' => '<div id="field-display-overview-wrapper">',
    '#suffix' => '</div>',
882 883 884
  );

  $field_label_options = array(
885 886 887 888
    'above' => t('Above'),
    'inline' => t('Inline'),
    'hidden' => t('<Hidden>'),
  );
889 890 891 892 893
  $extra_visibility_options = array(
    'visible' => t('Visible'),
    'hidden' => t('Hidden'),
  );

894
  // Field rows.
895
  foreach ($instances as $name => $instance) {
896
    $field = field_info_field($instance['field_name']);
897
    $display = $instance['display'][$view_mode];
898 899 900 901 902 903 904 905 906 907 908 909 910
    $table[$name] = array(
      '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
      '#row_type' => 'field',
      '#region_callback' => 'field_ui_display_overview_row_region',
      '#js_settings' => array(
        'rowHandler' => 'field',
        'defaultFormatter' => $field_types[$field['type']]['default_formatter'],
      ),
      'human_name' => array(
        '#markup' => check_plain($instance['label']),
      ),
      'weight' => array(
        '#type' => 'textfield',
911 912
        '#title' => t('Weight for @title', array('@title' => $instance['label'])),
        '#title_display' => 'invisible',
913 914 915 916 917 918 919
        '#default_value' => $display['weight'],
        '#size' => 3,
        '#attributes' => array('class' => array('field-weight')),
      ),
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
920 921
          '#title' => t('Label display for @title', array('@title' => $instance['label'])),
          '#title_display' => 'invisible',
922
          '#options' => $table['#parent_options'],
923
          '#empty_value' => '',
924 925 926 927 928 929 930 931 932 933 934
          '#attributes' => array('class' => array('field-parent')),
          '#parents' => array('fields', $name, 'parent'),
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $name,
          '#attributes' => array('class' => array('field-name')),
        ),
      ),
      'label' => array(
        '#type' => 'select',
935 936
        '#title' => t('Label display for @title', array('@title' => $instance['label'])),
        '#title_display' => 'invisible',
937 938 939
        '#options' => $field_label_options,
        '#default_value' => $display['label'],
      ),
940
    );
941 942 943

    $formatter_options = field_ui_formatter_options($field['type']);
    $formatter_options['hidden'] = t('<Hidden>');
944 945 946
    $table[$name]['format'] = array(
      'type' => array(
        '#type' => 'select',
947 948
        '#title' => t('Formatter for @title', array('@title' => $instance['label'])),
        '#title_display' => 'invisible',
949 950 951 952
        '#options' => $formatter_options,
        '#default_value' => $display['type'],
        '#parents' => array('fields', $name, 'type'),
        '#attributes' => array('class' => array('field-formatter-type')),
953
      ),
954
      'settings_edit_form' => array(),
955
    );
956

957 958 959 960
    // Formatter settings.

    // Check the currently selected formatter, and merge persisted values for
    // formatter settings.
961 962
    if (isset($form_state['values']['fields'][$name]['type'])) {
      $formatter_type = $form_state['values']['fields'][$name]['type'];
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
    }
    else {
      $formatter_type = $display['type'];
    }
    if (isset($form_state['formatter_settings'][$name])) {
      $settings = $form_state['formatter_settings'][$name];
    }
    else {
      $settings = $display['settings'];
    }
    $settings += field_info_formatter_settings($formatter_type);

    $instance['display'][$view_mode]['type'] = $formatter_type;
    $formatter = field_info_formatter_types($formatter_type);
    $instance['display'][$view_mode]['module'] = $formatter['module'];
    $instance['display'][$view_mode]['settings'] = $settings;

    // Base button element for the various formatter settings actions.
    $base_button = array(
982
      '#submit' => array('field_ui_display_overview_multistep_submit'),
983
      '#ajax' => array(
984
        'callback' => 'field_ui_display_overview_multistep_js',
985 986 987 988 989 990 991 992 993
        'wrapper' => 'field-display-overview-wrapper',
        'effect' => 'fade',
      ),
      '#field_name' => $name,
    );

    if ($form_state['formatter_settings_edit'] == $name) {
      // We are currently editing this field's formatter settings. Display the
      // settings form and submit buttons.
994
      $table[$name]['format']['settings_edit_form'] = array();
995 996

      $settings_form = array();
997
      $function = $formatter['module'] . '_field_formatter_settings_form';
998 999 1000 1001 1002 1003 1004
      if (function_exists($function)) {
        $settings_form = $function($field, $instance, $view_mode, $form, $form_state);
      }

      if ($settings_form) {
        $table[$name]['format']['#cell_attributes'] = array('colspan' => 3);
        $table[$name]['format']['settings_edit_form'] = array(
1005 1006
          '#type' => 'container',
          '#attributes' => array('class' => array('field-formatter-settings-edit-form')),
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
          '#parents' => array('fields', $name, 'settings_edit_form'),
          'label' => array(
            '#markup' => t('Format settings:') . ' <span class="formatter-name">' . $formatter['label'] . '</span>',
          ),
          'settings' => $settings_form,
          'actions' => array(
            '#type' => 'actions',
            'save_settings' => $base_button + array(
              '#type' => 'submit',
              '#name' => $name . '_formatter_settings_update',
              '#value' => t('Update'),
              '#op' => 'update',
            ),
            'cancel_settings' => $base_button + array(
              '#type' => 'submit',
              '#name' => $name . '_formatter_settings_cancel',
              '#value' => t('Cancel'),
              '#op' => 'cancel',
              // Do not check errors for the 'Cancel' button, but make sure we
              // get the value of the 'formatter type' select.
              '#limit_validation_errors' => array(array('fields', $name, 'type')),
            ),
          ),
1030
        );
1031
        $table[$name]['#attributes']['class'][] = 'field-formatter-settings-editing';
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
      }
    }
    else {
      // Display a summary of the current formatter settings.
      $summary = module_invoke($formatter['module'], 'field_formatter_settings_summary', $field, $instance, $view_mode);
      $table[$name]['settings_summary'] = array();
      $table[$name]['settings_edit'] = array();
      if ($summary) {
        $table[$name]['settings_summary'] = array(
          '#markup' => '<div class="field-formatter-summary">' . $summary . '</div>',
1042
          '#cell_attributes' => array('class' => array('field-formatter-summary-cell')),
1043 1044 1045 1046 1047 1048 1049
        );
        $table[$name]['settings_edit'] = $base_button + array(
          '#type' => 'image_button',
          '#name' => $name . '_formatter_settings_edit',
          '#src' => 'misc/configure.png',
          '#attributes' => array('class' => array('field-formatter-settings-edit'), 'alt' => t('Edit')),
          '#op' => 'edit',
1050 1051 1052
          // Do not check errors for the 'Edit' button, but make sure we get
          // the value of the 'formatter type' select.
          '#limit_validation_errors' => array(array('fields', $name, 'type')),
1053 1054 1055 1056 1057
          '#prefix' => '<div class="field-formatter-settings-edit-wrapper">',
          '#suffix' => '</div>',
        );
      }
    }
1058 1059 1060 1061 1062
  }

  // Non-field elements.
  foreach ($extra_fields as $name => $extra_field) {
    $display = $extra_field['display'][$view_mode];
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
    $table[$name] = array(
      '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
      '#row_type' => 'extra_field',
      '#region_callback' => 'field_ui_display_overview_row_region',
      '#js_settings' => array('rowHandler' => 'field'),
      'human_name' => array(
        '#markup' => check_plain($extra_field['label']),
      ),
      'weight' => array(
        '#type' => 'textfield',
1073 1074
        '#title' => t('Weight for @title', array('@title' => $extra_field['label'])),
        '#title_display' => 'invisible',
1075 1076 1077 1078 1079 1080 1081
        '#default_value' => $display['weight'],
        '#size' => 3,
        '#attributes' => array('class' => array('field-weight')),
      ),
      'parent_wrapper' => array(
        'parent' => array(
          '#type' => 'select',
1082 1083
          '#title' => t('Parents for @title', array('@title' => $extra_field['label'])),
          '#title_display' => 'invisible',
1084
          '#options' => $table['#parent_options'],
1085
          '#empty_value' => '',
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
          '#attributes' => array('class' => array('field-parent')),
          '#parents' => array('fields', $name, 'parent'),
        ),
        'hidden_name' => array(
          '#type' => 'hidden',
          '#default_value' => $name,
          '#attributes' => array('class' => array('field-name')),
        ),
      ),
      'empty_cell' => array(
        '#markup' => '&nbsp;',
      ),
      'format' => array(
        'type' => array(
          '#type' => 'select',
1101 1102
          '#title' => t('Visibility for @title', array('@title' => $extra_field['label'])),
          '#title_display' => 'invisible',
1103 1104 1105 1106 1107 1108 1109 1110
          '#options' => $extra_visibility_options,
          '#default_value' => $display['visible'] ? 'visible' : 'hidden',
          '#parents' => array('fields', $name, 'type'),
          '#attributes' => array('class' => array('field-formatter-type')),
        ),
      ),
      'settings_summary' => array(),
      'settings_edit' => array(),
1111 1112
    );
  }
1113

1114
  $form['fields'] = $table;
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

  // Custom display settings.
  if ($view_mode == 'default') {
    $form['modes'] = array(
      '#type' => 'fieldset',
      '#title' => t('Custom display settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    // Collect options and default values for the 'Custom display settings'
    // checkboxes.
    $options = array();
    $default = array();
    $entity_info = entity_get_info($entity_type);
    $view_modes = $entity_info['view modes'];
    $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
    foreach ($view_modes as $view_mode_name => $view_mode_info) {
      $options[$view_mode_name] = $view_mode_info['label'];
      if (!empty($view_mode_settings[$view_mode_name]['custom_settings'])) {
        $default[] = $view_mode_name;
      }
1136
    }
1137 1138
    $form['modes']['view_modes_custom'] = array(
      '#type' => 'checkboxes',
1139
      '#title' => t('Use custom display settings for the following view modes'),
1140 1141 1142
      '#options' => $options,
      '#default_value' => $default,
    );
1143 1144
  }

1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
  // In overviews involving nested rows from contributed modules (i.e
  // field_group), the 'format type' selects can trigger a series of changes in
  // child rows. The #ajax behavior is therefore not attached directly to the
  // selects, but triggered by the client-side script through a hidden #ajax
  // 'Refresh' button. A hidden 'refresh_rows' input tracks the name of
  // affected rows.
  $form['refresh_rows'] = array('#type' => 'hidden');
  $form['refresh'] = array(
    '#type' => 'submit',
    '#value' => t('Refresh'),
    '#op' => 'refresh_table',
    '#submit' => array('field_ui_display_overview_multistep_submit'),
    '#ajax' => array(
      'callback' => 'field_ui_display_overview_multistep_js',
      'wrapper' => 'field-display-overview-wrapper',
      'effect' => 'fade',
      // The button stays hidden, so we hide the AJAX spinner too. Ad-hoc
      // spinners will be added manually by the client-side script.
      'progress' => 'none',
    ),
  );

1167 1168
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
1169 1170 1171

  $form['#attached']['js'][] = drupal_get_path('module', 'field_ui') . '/field_ui.js';
  $form['#attached']['css'][] = drupal_get_path('module', 'field_ui') . '/field_ui.css';
1172

1173
  // Add tabledrag behavior.
1174 1175
  $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'order', 'sibling', 'field-weight');
  $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
1176

1177 1178 1179
  return $form;
}

1180 1181

/**
1182
 * Form submit handler for multistep buttons on the 'Manage display' screen.
1183
 */
1184
function field_ui_display_overview_multistep_submit($form, &$form_state) {
1185 1186 1187 1188 1189 1190
  $trigger = $form_state['triggering_element'];
  $op = $trigger['#op'];

  switch ($op) {
    case 'edit':
      // Store the field whose settings are currently being edited.
1191
      $field_name = $trigger['#field_name'];
1192 1193 1194 1195
      $form_state['formatter_settings_edit'] = $field_name;
      break;

    case 'update':
1196 1197 1198
      // Store the saved settings, and set the field back to 'non edit' mode.
      $field_name = $trigger['#field_name'];
      $values = $form_state['values']['fields'][$field_name]['settings_edit_form']['settings'];
1199
      $form_state['formatter_settings'][$field_name] = $values;
1200 1201 1202
      unset($form_state['formatter_settings_edit']);
      break;

1203
    case 'cancel':
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
      // Set the field back to 'non edit' mode.
      unset($form_state['formatter_settings_edit']);
      break;

    case 'refresh_table':
      // If the currently edited field is one of the rows to be refreshed, set
      // it back to 'non edit' mode.
      $updated_rows = explode(' ', $form_state['values']['refresh_rows']);
      if (isset($form_state['formatter_settings_edit']) && in_array($form_state['formatter_settings_edit'], $updated_rows)) {
        unset($form_state['formatter_settings_edit']);
      }
1215 1216 1217 1218 1219 1220 1221
      break;
  }

  $form_state['rebuild'] = TRUE;
}

/**
1222
 * AJAX handler for multistep buttons on the 'Manage display' screen.
1223
 */
1224
function field_ui_display_overview_multistep_js($form, &$form_state) {
1225 1226 1227
  $trigger = $form_state['triggering_element'];
  $op = $trigger['#op'];

1228
  // Pick the elements that need ro receive the ajax-new-content effect.
1229 1230
  switch ($op) {
    case 'edit':
1231 1232
      $updated_rows = array($trigger['#field_name']);
      $updated_columns = array('format');
1233 1234 1235 1236
      break;

    case 'update':
    case 'cancel':
1237 1238
      $updated_rows = array($trigger['#field_name']);
      $updated_columns = array('format', 'settings_summary', 'settings_edit');
1239 1240
      break;

1241 1242 1243 1244 1245
    case 'refresh_table':
      $updated_rows = array_values(explode(' ', $form_state['values']['refresh_rows']));
      $updated_columns = array('settings_summary', 'settings_edit');
      break;
  }
1246

webchick's avatar