Projet

Général

Profil

Paste
Télécharger (23,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_bulk_operations / actions / modify.action.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file VBO action to modify entity values (properties and fields).
5
 */
6

    
7
// Specifies that all available values should be shown to the user for editing.
8
define('VBO_MODIFY_ACTION_ALL', '_all_');
9

    
10
function views_bulk_operations_modify_action_info() {
11
  return array('views_bulk_operations_modify_action' => array(
12
    'type' => 'entity',
13
    'label' => t('Modify entity values'),
14
    'behavior' => array('changes_property'),
15
    // This action only works when invoked through VBO. That's why it's
16
    // declared as non-configurable to prevent it from being shown in the
17
    // "Create an advanced action" dropdown on admin/config/system/actions.
18
    'configurable' => FALSE,
19
    'vbo_configurable' => TRUE,
20
    'triggers' => array('any'),
21
  ));
22
}
23

    
24
/**
25
 * Action function.
26
 *
27
 * Goes through new values and uses them to modify the passed entity by either
28
 * replacing the existing values, or appending to them (based on user input).
29
 */
30
function views_bulk_operations_modify_action($entity, $context) {
31
  list(,,$bundle_name) = entity_extract_ids($context['entity_type'], $entity);
32
  // Handle Field API fields.
33
  if (!empty($context['selected']['bundle_' . $bundle_name])) {
34
    // The pseudo entity is cloned so that changes to it don't get carried
35
    // over to the next execution.
36
    $pseudo_entity = clone $context['entities'][$bundle_name];
37
    foreach ($context['selected']['bundle_' . $bundle_name] as $key) {
38
      // Get this field's language. We can just pull it from the pseudo entity
39
      // as it was created using field_attach_form and entity_language so it's
40
      // already been figured out if this field is translatable or not and
41
      // applied the appropriate language code to the field
42
      $language = key($pseudo_entity->{$key});
43
      // Replace any tokens that might exist in the field columns.
44
      foreach ($pseudo_entity->{$key}[$language] as $delta => &$item) {
45
        foreach ($item as $column => $value) {
46
          if (is_string($value)) {
47
            $item[$column] = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
48
          }
49
        }
50
      }
51

    
52
      if (in_array($key, $context['append']['bundle_' . $bundle_name]) && !empty($entity->$key)) {
53
        $entity->{$key}[$language] = array_merge($entity->{$key}[$language], $pseudo_entity->{$key}[$language]);
54

    
55
        // Check if we breached cardinality, and notify the user.
56
        $field_info = field_info_field($key);
57
        $field_count = count($entity->{$key}[$language]);
58
        if ($field_info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $field_count > $field_info['cardinality']) {
59
          $entity_label = entity_label($context['entity_type'], $entity);
60
          $warning = t('Tried to set !field_count values for field !field_name that supports a maximum of !cardinality.',
61
                       array('!field_count' => $field_count,
62
                             '!field_name' => $field_info['field_name'],
63
                             '!cardinality' => $field_info['cardinality']));
64
          drupal_set_message($warning, 'warning', FALSE);
65
        }
66

    
67
        // Prevent storing duplicate references.
68
        if (strpos($field_info['type'], 'reference') !== FALSE) {
69
          $entity->{$key}[$language] = array_unique($entity->{$key}[LANGUAGE_NONE], SORT_REGULAR);
70
        }
71
      }
72
      else {
73
        $entity->{$key}[$language] = $pseudo_entity->{$key}[$language];
74
      }
75
    }
76
  }
77

    
78
  // Handle properties.
79
  if (!empty($context['selected']['properties'])) {
80
    // Use the wrapper to set property values, since some properties need
81
    // additional massaging by their setter callbacks.
82
    // The wrapper will automatically modify $entity itself.
83
    $wrapper = entity_metadata_wrapper($context['entity_type'], $entity);
84
    foreach ($context['selected']['properties'] as $key) {
85
      if (in_array($key, $context['append']['properties'])) {
86
        $old_values = $wrapper->$key->value();
87
        $wrapper->$key->set($context['properties'][$key]);
88
        $new_values = $wrapper->{$key}->value();
89
        $all_values = array_merge($old_values, $new_values);
90
        $wrapper->$key->set($all_values);
91
      }
92
      else {
93
        $value = $context['properties'][$key];
94
        if (is_string($value)) {
95
          $value = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
96
        }
97
        $wrapper->$key->set($value);
98
      }
99
    }
100
  }
101
}
102

    
103
/**
104
 * Action form function.
105
 *
106
 * Displays form elements for properties acquired through Entity Metadata
107
 * (hook_entity_property_info()), as well as field widgets for each
108
 * entity bundle, as provided by field_attach_form().
109
 */
110
function views_bulk_operations_modify_action_form($context, &$form_state) {
111
  // This action form uses admin-provided settings. If they were not set, pull the defaults now.
112
  if (!isset($context['settings'])) {
113
    $context['settings'] = views_bulk_operations_modify_action_views_bulk_operations_form_options();
114
  }
115

    
116
  $form_state['entity_type'] = $entity_type = $context['entity_type'];
117
  // For Field API integration to work, a pseudo-entity is constructed for each
118
  // bundle that has fields available for editing.
119
  // The entities then get passed to Field API functions
120
  // (field_attach_form(), field_attach_form_validate(), field_attach_submit()),
121
  // and filled with form data.
122
  // After submit, the pseudo-entities get passed to the actual action
123
  // (views_bulk_operations_modify_action()) which copies the data from the
124
  // relevant pseudo-entity constructed here to the actual entity being modified.
125
  $form_state['entities'] = array();
126

    
127
  $info = entity_get_info($entity_type);
128
  $properties = _views_bulk_operations_modify_action_get_properties($entity_type, $context['settings']['display_values']);
129
  $bundles = _views_bulk_operations_modify_action_get_bundles($entity_type, $context);
130

    
131
  $form['#attached']['css'][] = drupal_get_path('module', 'views_bulk_operations') . '/css/modify.action.css';
132
  $form['#tree'] = TRUE;
133

    
134
  if (!empty($properties)) {
135
    $form['properties'] = array(
136
      '#type' => 'fieldset',
137
      '#title' => 'Properties',
138
    );
139
    $form['properties']['show_value'] = array(
140
      '#suffix' => '<div class="clearfix"></div>',
141
    );
142

    
143
    foreach ($properties as $key => $property) {
144
      $form['properties']['show_value'][$key] = array(
145
        '#type' => 'checkbox',
146
        '#title' => $property['label'],
147
      );
148

    
149
      $determined_type = ($property['type'] == 'boolean') ? 'checkbox' : 'textfield';
150
      $form['properties'][$key] = array(
151
        '#type' => $determined_type,
152
        '#title' => $property['label'],
153
        '#description' => $property['description'],
154
        '#states' => array(
155
          'visible' => array(
156
            '#edit-properties-show-value-' . str_replace('_', '-', $key) => array('checked' => TRUE),
157
          ),
158
        ),
159
      );
160
      // The default #maxlength for textfields is 128, while most varchar
161
      // columns hold 255 characters, which makes it a saner default here.
162
      if ($determined_type == 'textfield') {
163
        $form['properties'][$key]['#maxlength'] = 255;
164
      }
165

    
166
      if (!empty($property['options list'])) {
167
        $form['properties'][$key]['#type'] = 'select';
168
        $form['properties'][$key]['#options'] = $property['options list']($key, array());
169

    
170
        if ($property['type'] == 'list') {
171
          $form['properties'][$key]['#type'] = 'checkboxes';
172

    
173
          $form['properties']['_append::' . $key] = array(
174
            '#type' => 'checkbox',
175
            '#title' => t('Add new value(s) to %label, instead of overwriting the existing values.', array('%label' => $property['label'])),
176
            '#states' => array(
177
              'visible' => array(
178
                '#edit-properties-show-value-' . $key => array('checked' => TRUE),
179
              ),
180
            ),
181
          );
182
        }
183
      }
184
    }
185
  }
186

    
187
  // Going to need this for multilingual nodes
188
  global $language;
189
  foreach ($bundles as $bundle_name => $bundle) {
190
    $bundle_key = $info['entity keys']['bundle'];
191
    $default_values = array();
192
    // If the bundle key exists, it must always be set on an entity.
193
    if (!empty($bundle_key)) {
194
      $default_values[$bundle_key] = $bundle_name;
195
    }
196
    $default_values['language'] = $language->language;
197
    $entity = entity_create($context['entity_type'], $default_values);
198
    $form_state['entities'][$bundle_name] = $entity;
199

    
200
    // Show the more detailed label only if the entity type has multiple bundles.
201
    // Otherwise, it would just be confusing.
202
    if (count($info['bundles']) > 1) {
203
      $label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
204
    }
205
    else {
206
      $label = t('Fields');
207
    }
208

    
209
    $form_key = 'bundle_' . $bundle_name;
210
    $form[$form_key] = array(
211
      '#type' => 'fieldset',
212
      '#title' => $label,
213
      '#parents' => array($form_key),
214
    );
215
    field_attach_form($context['entity_type'], $entity, $form[$form_key], $form_state, entity_language($context['entity_type'], $entity));
216
    // Now that all the widgets have been added, sort them by #weight.
217
    // This ensures that they will stay in the correct order when they get
218
    // assigned new weights.
219
    uasort($form[$form_key], 'element_sort');
220

    
221
    $display_values = $context['settings']['display_values'];
222
    $instances = field_info_instances($entity_type, $bundle_name);
223
    $weight = 0;
224
    foreach (element_get_visible_children($form[$form_key]) as $field_name) {
225
      // For our use case it makes no sense for any field widget to be required.
226
      if (isset($form[$form_key][$field_name]['#language'])) {
227
        $field_language = $form[$form_key][$field_name]['#language'];
228
        _views_bulk_operations_modify_action_unset_required($form[$form_key][$field_name][$field_language]);
229
      }
230

    
231
      // The admin has specified which fields to display, but this field didn't
232
      // make the cut. Hide it with #access => FALSE and move on.
233
      if (empty($display_values[VBO_MODIFY_ACTION_ALL]) && empty($display_values[$bundle_name . '::' . $field_name])) {
234
        $form[$form_key][$field_name]['#access'] = FALSE;
235
        continue;
236
      }
237

    
238
      if (isset($instances[$field_name])) {
239
        $field = $instances[$field_name];
240
        $form[$form_key]['show_value'][$field_name] = array(
241
          '#type' => 'checkbox',
242
          '#title' => $field['label'],
243
        );
244
        $form[$form_key][$field_name]['#states'] = array(
245
          'visible' => array(
246
            '#edit-bundle-' . str_replace('_', '-', $bundle_name) . '-show-value-' . str_replace('_', '-', $field_name) => array('checked' => TRUE),
247
          ),
248
        );
249
        // All field widgets get reassigned weights so that additional elements
250
        // added between them (such as "_append") can be properly ordered.
251
        $form[$form_key][$field_name]['#weight'] = $weight++;
252

    
253
        $field_info = field_info_field($field_name);
254
        if ($field_info['cardinality'] != 1) {
255
          $form[$form_key]['_append::' . $field_name] = array(
256
            '#type' => 'checkbox',
257
            '#title' => t('Add new value(s) to %label, instead of overwriting the existing values.', array('%label' => $field['label'])),
258
            '#states' => array(
259
              'visible' => array(
260
                '#edit-bundle-' . str_replace('_', '-', $bundle_name) . '-show-value-' . str_replace('_', '-', $field_name) => array('checked' => TRUE),
261
              ),
262
            ),
263
            '#weight' => $weight++,
264
          );
265
        }
266
      }
267
    }
268

    
269
    // Add a clearfix below the checkboxes so that the widgets are not floated.
270
    $form[$form_key]['show_value']['#suffix'] = '<div class="clearfix"></div>';
271
    $form[$form_key]['show_value']['#weight'] = -1;
272
  }
273

    
274
  // If the form has only one group (for example, "Properties"), remove the
275
  // title and the fieldset, since there's no need to visually group values.
276
  $form_elements = element_get_visible_children($form);
277
  if (count($form_elements) == 1) {
278
    $element_key = reset($form_elements);
279
    unset($form[$element_key]['#type']);
280
    unset($form[$element_key]['#title']);
281

    
282
    // Get a list of all elements in the group, and filter out the non-values.
283
    $values = element_get_visible_children($form[$element_key]);
284
    foreach ($values as $index => $key) {
285
      if ($key == 'show_value' || substr($key, 0, 1) == '_') {
286
        unset($values[$index]);
287
      }
288
    }
289
    // If the group has only one value, no need to hide it through #states.
290
    if (count($values) == 1) {
291
      $value_key = reset($values);
292
      $form[$element_key]['show_value'][$value_key]['#type'] = 'value';
293
      $form[$element_key]['show_value'][$value_key]['#value'] = TRUE;
294
    }
295
  }
296

    
297
  if (module_exists('token') && $context['settings']['show_all_tokens']) {
298
    $token_type = str_replace('_', '-', $entity_type);
299
    $form['tokens'] = array(
300
      '#type' => 'fieldset',
301
      '#title' => 'Available tokens',
302
      '#collapsible' => TRUE,
303
      '#collapsed' => TRUE,
304
      '#weight' => 998,
305
    );
306
    $form['tokens']['tree'] = array(
307
      '#theme' => 'token_tree',
308
      '#token_types' => array($token_type, 'site'),
309
      '#global_types' => array(),
310
      '#dialog' => TRUE,
311
    );
312
  }
313

    
314
  return $form;
315
}
316

    
317
/**
318
 * Action form validate function.
319
 *
320
 * Checks that the user selected at least one value to modify, validates
321
 * properties and calls Field API to validate fields for each bundle.
322
 */
323
function views_bulk_operations_modify_action_validate($form, &$form_state) {
324
  // The form structure for "Show" checkboxes is a bit bumpy.
325
  $search = array('properties');
326
  foreach ($form_state['entities'] as $bundle => $entity) {
327
    $search[] = 'bundle_' . $bundle;
328
  }
329

    
330
  $has_selected = FALSE;
331
  foreach ($search as $group) {
332
    // Store names of selected and appended entity values in a nicer format.
333
    $form_state['selected'][$group] = array();
334
    $form_state['append'][$group] = array();
335

    
336
    // This group has no values, move on.
337
    if (!isset($form_state['values'][$group])) {
338
      continue;
339
    }
340

    
341
    foreach ($form_state['values'][$group]['show_value'] as $key => $value) {
342
      if ($value) {
343
        $has_selected = TRUE;
344
        $form_state['selected'][$group][] = $key;
345
      }
346
      if (!empty($form_state['values'][$group]['_append::' . $key])) {
347
        $form_state['append'][$group][] = $key;
348
        unset($form_state['values'][$group]['_append::' . $key]);
349
      }
350
    }
351
    unset($form_state['values'][$group]['show_value']);
352
  }
353

    
354
  if (!$has_selected) {
355
    form_set_error('', t('You must select at least one value to modify.'));
356
    return;
357
  }
358

    
359
  // Use the wrapper to validate property values.
360
  if (!empty($form_state['selected']['properties'])) {
361
    // The entity used is irrelevant, and we can't rely on
362
    // $form_state['entities'] being non-empty, so a new one is created.
363
    $info = entity_get_info($form_state['entity_type']);
364
    $bundle_key = $info['entity keys']['bundle'];
365
    $default_values = array();
366
    // If the bundle key exists, it must always be set on an entity.
367
    if (!empty($bundle_key)) {
368
      $bundle_names = array_keys($info['bundles']);
369
      $bundle_name = reset($bundle_names);
370
      $default_values[$bundle_key] = $bundle_name;
371
    }
372
    $entity = entity_create($form_state['entity_type'], $default_values);
373
    $wrapper = entity_metadata_wrapper($form_state['entity_type'], $entity);
374

    
375
    $properties = _views_bulk_operations_modify_action_get_properties($form_state['entity_type']);
376
    foreach ($form_state['selected']['properties'] as $key) {
377
      $value = $form_state['values']['properties'][$key];
378
      if (!$wrapper->$key->validate($value)) {
379
        $label = $properties[$key]['label'];
380
        form_set_error('properties][' . $key, t('%label contains an invalid value.', array('%label' => $label)));
381
      }
382
    }
383
  }
384

    
385
  foreach ($form_state['entities'] as $bundle_name => $entity) {
386
    field_attach_form_validate($form_state['entity_type'], $entity, $form['bundle_' . $bundle_name], $form_state);
387
  }
388
}
389

    
390
/**
391
 * Action form submit function.
392
 *
393
 * Fills each constructed entity with property and field values, then
394
 * passes them to views_bulk_operations_modify_action().
395
 */
396
function views_bulk_operations_modify_action_submit($form, $form_state) {
397
  foreach ($form_state['entities'] as $bundle_name => $entity) {
398
    field_attach_submit($form_state['entity_type'], $entity, $form['bundle_' . $bundle_name], $form_state);
399
  }
400

    
401
  return array(
402
    'append' => $form_state['append'],
403
    'selected' => $form_state['selected'],
404
    'entities' => $form_state['entities'],
405
    'properties' => isset($form_state['values']['properties']) ? $form_state['values']['properties'] : array(),
406
  );
407
}
408

    
409
/**
410
 * Returns all properties that can be modified.
411
 *
412
 * Properties that can't be changed are entity keys, timestamps, and the ones
413
 * without a setter callback.
414
 *
415
 * @param $entity_type
416
 *   The entity type whose properties will be fetched.
417
 * @param $display_values
418
 *   An optional, admin-provided list of properties and fields that should be
419
 *   displayed for editing, used to filter the returned list of properties.
420
 */
421
function _views_bulk_operations_modify_action_get_properties($entity_type, $display_values = NULL) {
422
  $properties = array();
423
  $info = entity_get_info($entity_type);
424

    
425
  // List of properties that can't be modified.
426
  $disabled_properties = array('created', 'changed');
427
  foreach (array('id', 'bundle', 'revision') as $key) {
428
    if (!empty($info['entity keys'][$key])) {
429
      $disabled_properties[] = $info['entity keys'][$key];
430
    }
431
  }
432
  // List of supported types.
433
  $supported_types = array('text', 'token', 'integer', 'decimal', 'date', 'duration',
434
                           'boolean', 'uri', 'list');
435
  $property_info = entity_get_property_info($entity_type);
436
  if (empty($property_info['properties'])) {
437
    // Stop here if no properties were found.
438
    return array();
439
  }
440

    
441
  foreach ($property_info['properties'] as $key => $property) {
442
    if (in_array($key, $disabled_properties)) {
443
      continue;
444
    }
445
    // Filter out properties that can't be set (they are usually generated by a
446
    // getter callback based on other properties, and not stored in the DB).
447
    if (empty($property['setter callback'])) {
448
      continue;
449
    }
450
    // Determine the property type. If it's empty (permitted), default to text.
451
    // If it's a list type such as list<boolean>, extract the "boolean" part.
452
    $property['type'] = empty($property['type']) ? 'text' : $property['type'];
453
    $type = $property['type'];
454
    if ($list_type = entity_property_list_extract_type($type)) {
455
      $type = $list_type;
456
      $property['type'] = 'list';
457
    }
458
    // Filter out non-supported types (such as the Field API fields that
459
    // Commerce adds to its entities so that they show up in tokens).
460
    if (!in_array($type, $supported_types)) {
461
      continue;
462
    }
463

    
464
    $properties[$key] = $property;
465
  }
466

    
467
  if (isset($display_values) && empty($display_values[VBO_MODIFY_ACTION_ALL])) {
468
    // Return only the properties that the admin specified.
469
    return array_intersect_key($properties, $display_values);
470
  }
471

    
472
  return $properties;
473
}
474

    
475
/**
476
 * Returns all bundles for which field widgets should be displayed.
477
 *
478
 * If the admin decided to limit the modify form to certain properties / fields
479
 * (through the action settings) then only bundles that have at least one field
480
 * selected are returned.
481
 *
482
 * @param $entity_type
483
 *   The entity type whose bundles will be fetched.
484
 * @param $context
485
 *   The VBO context variable.
486
 */
487
function _views_bulk_operations_modify_action_get_bundles($entity_type, $context) {
488
  $bundles = array();
489

    
490
  $view = $context['view'];
491
  $vbo = _views_bulk_operations_get_field($view);
492
  $display_values = $context['settings']['display_values'];
493
  $info = entity_get_info($entity_type);
494
  $bundle_key = $info['entity keys']['bundle'];
495

    
496
  // Check if this View has a filter on the bundle key and assemble a list
497
  // of allowed bundles according to the filter.
498
  $filtered_bundles = array_keys($info['bundles']);
499

    
500
  // Go over all the filters and find any relevant ones.
501
  foreach ($view->filter as $key => $filter) {
502
    // Check it's the right field on the right table.
503
    if ($filter->table == $vbo->table && $filter->field == $bundle_key) {
504
      // Exposed filters may have no bundles, so check that there is a value.
505
      if (empty($filter->value)) {
506
        continue;
507
      }
508

    
509
      $operator = $filter->operator;
510
      if ($operator == 'in') {
511
        $filtered_bundles = array_intersect($filtered_bundles, $filter->value);
512
      }
513
      elseif ($operator == 'not in') {
514
        $filtered_bundles = array_diff($filtered_bundles, $filter->value);
515
      }
516
    }
517
  }
518

    
519
  foreach ($info['bundles'] as $bundle_name => $bundle) {
520
    // The view is limited to specific bundles, but this bundle isn't one of
521
    // them. Ignore it.
522
    if (!in_array($bundle_name, $filtered_bundles)) {
523
      continue;
524
    }
525

    
526
    $instances = field_info_instances($entity_type, $bundle_name);
527
    // Ignore bundles that don't have any field instances attached.
528
    if (empty($instances)) {
529
      continue;
530
    }
531

    
532
    $has_enabled_fields = FALSE;
533
    foreach ($display_values as $key) {
534
      if (strpos($key, $bundle_name . '::') !== FALSE) {
535
        $has_enabled_fields = TRUE;
536
      }
537
    }
538
    // The admin has either specified that all values should be modifiable, or
539
    // selected at least one field belonging to this bundle.
540
    if (!empty($display_values[VBO_MODIFY_ACTION_ALL]) || $has_enabled_fields) {
541
      $bundles[$bundle_name] = $bundle;
542
    }
543
  }
544

    
545
  return $bundles;
546
}
547

    
548
/**
549
 * Helper function that recursively strips #required from field widgets.
550
 */
551
function _views_bulk_operations_modify_action_unset_required(&$element) {
552
  unset($element['#required']);
553
  foreach (element_children($element) as $key) {
554
    _views_bulk_operations_modify_action_unset_required($element[$key]);
555
  }
556
}
557

    
558
/**
559
 * VBO settings form function.
560
 */
561
function views_bulk_operations_modify_action_views_bulk_operations_form_options() {
562
  $options['show_all_tokens'] = TRUE;
563
  $options['display_values'] = array(VBO_MODIFY_ACTION_ALL);
564
  return $options;
565
}
566

    
567
/**
568
 * The settings form for this action.
569
 */
570
function views_bulk_operations_modify_action_views_bulk_operations_form($options, $entity_type, $dom_id) {
571
  // Initialize default values.
572
  if (empty($options)) {
573
    $options = views_bulk_operations_modify_action_views_bulk_operations_form_options();
574
  }
575

    
576
  $form['show_all_tokens'] = array(
577
    '#type' => 'checkbox',
578
    '#title' => t('Show available tokens'),
579
    '#description' => t('Check this to show a list of all available tokens in the bottom of the form. Requires the token module.'),
580
    '#default_value' => $options['show_all_tokens'],
581
  );
582

    
583
  $info = entity_get_info($entity_type);
584
  $properties = _views_bulk_operations_modify_action_get_properties($entity_type);
585
  $values = array(VBO_MODIFY_ACTION_ALL => t('- All -'));
586
  foreach ($properties as $key => $property) {
587
    $label = t('Properties');
588
    $values[$label][$key] = $property['label'];
589
  }
590
  foreach ($info['bundles'] as $bundle_name => $bundle) {
591
    $bundle_key = $info['entity keys']['bundle'];
592
    // Show the more detailed label only if the entity type has multiple bundles.
593
    // Otherwise, it would just be confusing.
594
    if (count($info['bundles']) > 1) {
595
      $label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
596
    }
597
    else {
598
      $label = t('Fields');
599
    }
600

    
601
    $instances = field_info_instances($entity_type, $bundle_name);
602
    foreach ($instances as $field_name => $field) {
603
      $values[$label][$bundle_name . '::' . $field_name] = $field['label'];
604
    }
605
  }
606

    
607
  $form['display_values'] = array(
608
    '#type' => 'select',
609
    '#title' => t('Display values'),
610
    '#options' => $values,
611
    '#multiple' => TRUE,
612
    '#description' => t('Select which values the action form should present to the user.'),
613
    '#default_value' => $options['display_values'],
614
    '#size' => 10,
615
  );
616
  return $form;
617
}