modify.action.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <?php
  2. /**
  3. * @file VBO action to modify entity values (properties and fields).
  4. */
  5. // Specifies that all available values should be shown to the user for editing.
  6. define('VBO_MODIFY_ACTION_ALL', '_all_');
  7. function views_bulk_operations_modify_action_info() {
  8. return array('views_bulk_operations_modify_action' => array(
  9. 'type' => 'entity',
  10. 'label' => t('Modify entity values'),
  11. 'behavior' => array('changes_property'),
  12. // This action only works when invoked through VBO. That's why it's
  13. // declared as non-configurable to prevent it from being shown in the
  14. // "Create an advanced action" dropdown on admin/config/system/actions.
  15. 'configurable' => FALSE,
  16. 'vbo_configurable' => TRUE,
  17. 'triggers' => array('any'),
  18. ));
  19. }
  20. /**
  21. * Action function.
  22. *
  23. * Goes through new values and uses them to modify the passed entity by either
  24. * replacing the existing values, or appending to them (based on user input).
  25. */
  26. function views_bulk_operations_modify_action($entity, $context) {
  27. list(,,$bundle_name) = entity_extract_ids($context['entity_type'], $entity);
  28. // Handle Field API fields.
  29. if (!empty($context['selected']['bundle_' . $bundle_name])) {
  30. // The pseudo entity is cloned so that changes to it don't get carried
  31. // over to the next execution.
  32. $pseudo_entity = clone $context['entities'][$bundle_name];
  33. foreach ($context['selected']['bundle_' . $bundle_name] as $key) {
  34. // Get this field's language. We can just pull it from the pseudo entity
  35. // as it was created using field_attach_form and entity_language so it's
  36. // already been figured out if this field is translatable or not and
  37. // applied the appropriate language code to the field
  38. $language = key($pseudo_entity->{$key});
  39. // Replace any tokens that might exist in the field columns.
  40. foreach ($pseudo_entity->{$key}[$language] as $delta => &$item) {
  41. foreach ($item as $column => $value) {
  42. if (is_string($value)) {
  43. $item[$column] = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
  44. }
  45. }
  46. }
  47. if (in_array($key, $context['append']['bundle_' . $bundle_name]) && !empty($entity->$key)) {
  48. $entity->{$key}[$language] = array_merge($entity->{$key}[$language], $pseudo_entity->{$key}[$language]);
  49. // Check if we breached cardinality, and notify the user.
  50. $field_info = field_info_field($key);
  51. $field_count = count($entity->{$key}[$language]);
  52. if ($field_info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $field_count > $field_info['cardinality']) {
  53. $entity_label = entity_label($context['entity_type'], $entity);
  54. $warning = t('Tried to set !field_count values for field !field_name that supports a maximum of !cardinality.',
  55. array('!field_count' => $field_count,
  56. '!field_name' => $field_info['field_name'],
  57. '!cardinality' => $field_info['cardinality']));
  58. drupal_set_message($warning, 'warning', FALSE);
  59. }
  60. // Prevent storing duplicate references.
  61. if (strpos($field_info['type'], 'reference') !== FALSE) {
  62. $entity->{$key}[$language] = array_unique($entity->{$key}[LANGUAGE_NONE], SORT_REGULAR);
  63. }
  64. }
  65. else {
  66. $entity->{$key}[$language] = $pseudo_entity->{$key}[$language];
  67. }
  68. }
  69. }
  70. // Handle properties.
  71. if (!empty($context['selected']['properties'])) {
  72. // Use the wrapper to set property values, since some properties need
  73. // additional massaging by their setter callbacks.
  74. // The wrapper will automatically modify $entity itself.
  75. $wrapper = entity_metadata_wrapper($context['entity_type'], $entity);
  76. foreach ($context['selected']['properties'] as $key) {
  77. if (in_array($key, $context['append']['properties'])) {
  78. $old_values = $wrapper->$key->value();
  79. $wrapper->$key->set($context['properties'][$key]);
  80. $new_values = $wrapper->{$key}->value();
  81. $all_values = array_merge($old_values, $new_values);
  82. $wrapper->$key->set($all_values);
  83. }
  84. else {
  85. $value = $context['properties'][$key];
  86. if (is_string($value)) {
  87. $value = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
  88. }
  89. $wrapper->$key->set($value);
  90. }
  91. }
  92. }
  93. }
  94. /**
  95. * Action form function.
  96. *
  97. * Displays form elements for properties acquired through Entity Metadata
  98. * (hook_entity_property_info()), as well as field widgets for each
  99. * entity bundle, as provided by field_attach_form().
  100. */
  101. function views_bulk_operations_modify_action_form($context, &$form_state) {
  102. // This action form uses admin-provided settings. If they were not set, pull the defaults now.
  103. if (!isset($context['settings'])) {
  104. $context['settings'] = views_bulk_operations_modify_action_views_bulk_operations_form_options();
  105. }
  106. $form_state['entity_type'] = $entity_type = $context['entity_type'];
  107. // For Field API integration to work, a pseudo-entity is constructed for each
  108. // bundle that has fields available for editing.
  109. // The entities then get passed to Field API functions
  110. // (field_attach_form(), field_attach_form_validate(), field_attach_submit()),
  111. // and filled with form data.
  112. // After submit, the pseudo-entities get passed to the actual action
  113. // (views_bulk_operations_modify_action()) which copies the data from the
  114. // relevant pseudo-entity constructed here to the actual entity being modified.
  115. $form_state['entities'] = array();
  116. $info = entity_get_info($entity_type);
  117. $properties = _views_bulk_operations_modify_action_get_properties($entity_type, $context['settings']['display_values']);
  118. $bundles = _views_bulk_operations_modify_action_get_bundles($entity_type, $context);
  119. $form['#attached']['css'][] = drupal_get_path('module', 'views_bulk_operations') . '/css/modify.action.css';
  120. $form['#tree'] = TRUE;
  121. if (!empty($properties)) {
  122. $form['properties'] = array(
  123. '#type' => 'fieldset',
  124. '#title' => 'Properties',
  125. );
  126. $form['properties']['show_value'] = array(
  127. '#suffix' => '<div class="clearfix"></div>',
  128. );
  129. foreach ($properties as $key => $property) {
  130. $form['properties']['show_value'][$key] = array(
  131. '#type' => 'checkbox',
  132. '#title' => $property['label'],
  133. );
  134. $determined_type = ($property['type'] == 'boolean') ? 'checkbox' : 'textfield';
  135. $form['properties'][$key] = array(
  136. '#type' => $determined_type,
  137. '#title' => $property['label'],
  138. '#description' => $property['description'],
  139. '#states' => array(
  140. 'visible' => array(
  141. '#edit-properties-show-value-' . str_replace('_', '-', $key) => array('checked' => TRUE),
  142. ),
  143. ),
  144. );
  145. // The default #maxlength for textfields is 128, while most varchar
  146. // columns hold 255 characters, which makes it a saner default here.
  147. if ($determined_type == 'textfield') {
  148. $form['properties'][$key]['#maxlength'] = 255;
  149. }
  150. if (!empty($property['options list'])) {
  151. $form['properties'][$key]['#type'] = 'select';
  152. $form['properties'][$key]['#options'] = $property['options list']($key, array());
  153. if ($property['type'] == 'list') {
  154. $form['properties'][$key]['#type'] = 'checkboxes';
  155. $form['properties']['_append::' . $key] = array(
  156. '#type' => 'checkbox',
  157. '#title' => t('Add new value(s) to %label, instead of overwriting the existing values.', array('%label' => $property['label'])),
  158. '#states' => array(
  159. 'visible' => array(
  160. '#edit-properties-show-value-' . $key => array('checked' => TRUE),
  161. ),
  162. ),
  163. );
  164. }
  165. }
  166. }
  167. }
  168. // Going to need this for multilingual nodes
  169. global $language;
  170. foreach ($bundles as $bundle_name => $bundle) {
  171. $bundle_key = $info['entity keys']['bundle'];
  172. $default_values = array();
  173. // If the bundle key exists, it must always be set on an entity.
  174. if (!empty($bundle_key)) {
  175. $default_values[$bundle_key] = $bundle_name;
  176. }
  177. $default_values['language'] = $language->language;
  178. $entity = entity_create($context['entity_type'], $default_values);
  179. $form_state['entities'][$bundle_name] = $entity;
  180. // Show the more detailed label only if the entity type has multiple bundles.
  181. // Otherwise, it would just be confusing.
  182. if (count($info['bundles']) > 1) {
  183. $label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
  184. }
  185. else {
  186. $label = t('Fields');
  187. }
  188. $form_key = 'bundle_' . $bundle_name;
  189. $form[$form_key] = array(
  190. '#type' => 'fieldset',
  191. '#title' => $label,
  192. '#parents' => array($form_key),
  193. );
  194. field_attach_form($context['entity_type'], $entity, $form[$form_key], $form_state, entity_language($context['entity_type'], $entity));
  195. // Now that all the widgets have been added, sort them by #weight.
  196. // This ensures that they will stay in the correct order when they get
  197. // assigned new weights.
  198. uasort($form[$form_key], 'element_sort');
  199. $display_values = $context['settings']['display_values'];
  200. $instances = field_info_instances($entity_type, $bundle_name);
  201. $weight = 0;
  202. foreach (element_get_visible_children($form[$form_key]) as $field_name) {
  203. // For our use case it makes no sense for any field widget to be required.
  204. if (isset($form[$form_key][$field_name]['#language'])) {
  205. $field_language = $form[$form_key][$field_name]['#language'];
  206. _views_bulk_operations_modify_action_unset_required($form[$form_key][$field_name][$field_language]);
  207. }
  208. // The admin has specified which fields to display, but this field didn't
  209. // make the cut. Hide it with #access => FALSE and move on.
  210. if (empty($display_values[VBO_MODIFY_ACTION_ALL]) && empty($display_values[$bundle_name . '::' . $field_name])) {
  211. $form[$form_key][$field_name]['#access'] = FALSE;
  212. continue;
  213. }
  214. if (isset($instances[$field_name])) {
  215. $field = $instances[$field_name];
  216. $form[$form_key]['show_value'][$field_name] = array(
  217. '#type' => 'checkbox',
  218. '#title' => $field['label'],
  219. );
  220. $form[$form_key][$field_name]['#states'] = array(
  221. 'visible' => array(
  222. '#edit-bundle-' . str_replace('_', '-', $bundle_name) . '-show-value-' . str_replace('_', '-', $field_name) => array('checked' => TRUE),
  223. ),
  224. );
  225. // All field widgets get reassigned weights so that additional elements
  226. // added between them (such as "_append") can be properly ordered.
  227. $form[$form_key][$field_name]['#weight'] = $weight++;
  228. $field_info = field_info_field($field_name);
  229. if ($field_info['cardinality'] != 1) {
  230. $form[$form_key]['_append::' . $field_name] = array(
  231. '#type' => 'checkbox',
  232. '#title' => t('Add new value(s) to %label, instead of overwriting the existing values.', array('%label' => $field['label'])),
  233. '#states' => array(
  234. 'visible' => array(
  235. '#edit-bundle-' . str_replace('_', '-', $bundle_name) . '-show-value-' . str_replace('_', '-', $field_name) => array('checked' => TRUE),
  236. ),
  237. ),
  238. '#weight' => $weight++,
  239. );
  240. }
  241. }
  242. }
  243. // Add a clearfix below the checkboxes so that the widgets are not floated.
  244. $form[$form_key]['show_value']['#suffix'] = '<div class="clearfix"></div>';
  245. $form[$form_key]['show_value']['#weight'] = -1;
  246. }
  247. // If the form has only one group (for example, "Properties"), remove the
  248. // title and the fieldset, since there's no need to visually group values.
  249. $form_elements = element_get_visible_children($form);
  250. if (count($form_elements) == 1) {
  251. $element_key = reset($form_elements);
  252. unset($form[$element_key]['#type']);
  253. unset($form[$element_key]['#title']);
  254. // Get a list of all elements in the group, and filter out the non-values.
  255. $values = element_get_visible_children($form[$element_key]);
  256. foreach ($values as $index => $key) {
  257. if ($key == 'show_value' || substr($key, 0, 1) == '_') {
  258. unset($values[$index]);
  259. }
  260. }
  261. // If the group has only one value, no need to hide it through #states.
  262. if (count($values) == 1) {
  263. $value_key = reset($values);
  264. $form[$element_key]['show_value'][$value_key]['#type'] = 'value';
  265. $form[$element_key]['show_value'][$value_key]['#value'] = TRUE;
  266. }
  267. }
  268. if (module_exists('token') && $context['settings']['show_all_tokens']) {
  269. $token_type = str_replace('_', '-', $entity_type);
  270. $form['tokens'] = array(
  271. '#type' => 'fieldset',
  272. '#title' => 'Available tokens',
  273. '#collapsible' => TRUE,
  274. '#collapsed' => TRUE,
  275. '#weight' => 998,
  276. );
  277. $form['tokens']['tree'] = array(
  278. '#theme' => 'token_tree',
  279. '#token_types' => array($token_type, 'site'),
  280. '#global_types' => array(),
  281. '#dialog' => TRUE,
  282. );
  283. }
  284. return $form;
  285. }
  286. /**
  287. * Action form validate function.
  288. *
  289. * Checks that the user selected at least one value to modify, validates
  290. * properties and calls Field API to validate fields for each bundle.
  291. */
  292. function views_bulk_operations_modify_action_validate($form, &$form_state) {
  293. // The form structure for "Show" checkboxes is a bit bumpy.
  294. $search = array('properties');
  295. foreach ($form_state['entities'] as $bundle => $entity) {
  296. $search[] = 'bundle_' . $bundle;
  297. }
  298. $has_selected = FALSE;
  299. foreach ($search as $group) {
  300. // Store names of selected and appended entity values in a nicer format.
  301. $form_state['selected'][$group] = array();
  302. $form_state['append'][$group] = array();
  303. // This group has no values, move on.
  304. if (!isset($form_state['values'][$group])) {
  305. continue;
  306. }
  307. foreach ($form_state['values'][$group]['show_value'] as $key => $value) {
  308. if ($value) {
  309. $has_selected = TRUE;
  310. $form_state['selected'][$group][] = $key;
  311. }
  312. if (!empty($form_state['values'][$group]['_append::' . $key])) {
  313. $form_state['append'][$group][] = $key;
  314. unset($form_state['values'][$group]['_append::' . $key]);
  315. }
  316. }
  317. unset($form_state['values'][$group]['show_value']);
  318. }
  319. if (!$has_selected) {
  320. form_set_error('', t('You must select at least one value to modify.'));
  321. return;
  322. }
  323. // Use the wrapper to validate property values.
  324. if (!empty($form_state['selected']['properties'])) {
  325. // The entity used is irrelevant, and we can't rely on
  326. // $form_state['entities'] being non-empty, so a new one is created.
  327. $info = entity_get_info($form_state['entity_type']);
  328. $bundle_key = $info['entity keys']['bundle'];
  329. $default_values = array();
  330. // If the bundle key exists, it must always be set on an entity.
  331. if (!empty($bundle_key)) {
  332. $bundle_names = array_keys($info['bundles']);
  333. $bundle_name = reset($bundle_names);
  334. $default_values[$bundle_key] = $bundle_name;
  335. }
  336. $entity = entity_create($form_state['entity_type'], $default_values);
  337. $wrapper = entity_metadata_wrapper($form_state['entity_type'], $entity);
  338. $properties = _views_bulk_operations_modify_action_get_properties($form_state['entity_type']);
  339. foreach ($form_state['selected']['properties'] as $key) {
  340. $value = $form_state['values']['properties'][$key];
  341. if (!$wrapper->$key->validate($value)) {
  342. $label = $properties[$key]['label'];
  343. form_set_error('properties][' . $key, t('%label contains an invalid value.', array('%label' => $label)));
  344. }
  345. }
  346. }
  347. foreach ($form_state['entities'] as $bundle_name => $entity) {
  348. field_attach_form_validate($form_state['entity_type'], $entity, $form['bundle_' . $bundle_name], $form_state);
  349. }
  350. }
  351. /**
  352. * Action form submit function.
  353. *
  354. * Fills each constructed entity with property and field values, then
  355. * passes them to views_bulk_operations_modify_action().
  356. */
  357. function views_bulk_operations_modify_action_submit($form, $form_state) {
  358. foreach ($form_state['entities'] as $bundle_name => $entity) {
  359. field_attach_submit($form_state['entity_type'], $entity, $form['bundle_' . $bundle_name], $form_state);
  360. }
  361. return array(
  362. 'append' => $form_state['append'],
  363. 'selected' => $form_state['selected'],
  364. 'entities' => $form_state['entities'],
  365. 'properties' => isset($form_state['values']['properties']) ? $form_state['values']['properties'] : array(),
  366. );
  367. }
  368. /**
  369. * Returns all properties that can be modified.
  370. *
  371. * Properties that can't be changed are entity keys, timestamps, and the ones
  372. * without a setter callback.
  373. *
  374. * @param $entity_type
  375. * The entity type whose properties will be fetched.
  376. * @param $display_values
  377. * An optional, admin-provided list of properties and fields that should be
  378. * displayed for editing, used to filter the returned list of properties.
  379. */
  380. function _views_bulk_operations_modify_action_get_properties($entity_type, $display_values = NULL) {
  381. $properties = array();
  382. $info = entity_get_info($entity_type);
  383. // List of properties that can't be modified.
  384. $disabled_properties = array('created', 'changed');
  385. foreach (array('id', 'bundle', 'revision') as $key) {
  386. if (!empty($info['entity keys'][$key])) {
  387. $disabled_properties[] = $info['entity keys'][$key];
  388. }
  389. }
  390. // List of supported types.
  391. $supported_types = array('text', 'token', 'integer', 'decimal', 'date', 'duration',
  392. 'boolean', 'uri', 'list');
  393. $property_info = entity_get_property_info($entity_type);
  394. if (empty($property_info['properties'])) {
  395. // Stop here if no properties were found.
  396. return array();
  397. }
  398. foreach ($property_info['properties'] as $key => $property) {
  399. if (in_array($key, $disabled_properties)) {
  400. continue;
  401. }
  402. // Filter out properties that can't be set (they are usually generated by a
  403. // getter callback based on other properties, and not stored in the DB).
  404. if (empty($property['setter callback'])) {
  405. continue;
  406. }
  407. // Determine the property type. If it's empty (permitted), default to text.
  408. // If it's a list type such as list<boolean>, extract the "boolean" part.
  409. $property['type'] = empty($property['type']) ? 'text' : $property['type'];
  410. $type = $property['type'];
  411. if ($list_type = entity_property_list_extract_type($type)) {
  412. $type = $list_type;
  413. $property['type'] = 'list';
  414. }
  415. // Filter out non-supported types (such as the Field API fields that
  416. // Commerce adds to its entities so that they show up in tokens).
  417. if (!in_array($type, $supported_types)) {
  418. continue;
  419. }
  420. $properties[$key] = $property;
  421. }
  422. if (isset($display_values) && empty($display_values[VBO_MODIFY_ACTION_ALL])) {
  423. // Return only the properties that the admin specified.
  424. return array_intersect_key($properties, $display_values);
  425. }
  426. return $properties;
  427. }
  428. /**
  429. * Returns all bundles for which field widgets should be displayed.
  430. *
  431. * If the admin decided to limit the modify form to certain properties / fields
  432. * (through the action settings) then only bundles that have at least one field
  433. * selected are returned.
  434. *
  435. * @param $entity_type
  436. * The entity type whose bundles will be fetched.
  437. * @param $context
  438. * The VBO context variable.
  439. */
  440. function _views_bulk_operations_modify_action_get_bundles($entity_type, $context) {
  441. $bundles = array();
  442. $view = $context['view'];
  443. $vbo = _views_bulk_operations_get_field($view);
  444. $display_values = $context['settings']['display_values'];
  445. $info = entity_get_info($entity_type);
  446. $bundle_key = $info['entity keys']['bundle'];
  447. // Check if this View has a filter on the bundle key and assemble a list
  448. // of allowed bundles according to the filter.
  449. $filtered_bundles = array_keys($info['bundles']);
  450. // Go over all the filters and find any relevant ones.
  451. foreach ($view->filter as $key => $filter) {
  452. // Check it's the right field on the right table.
  453. if ($filter->table == $vbo->table && $filter->field == $bundle_key) {
  454. // Exposed filters may have no bundles, so check that there is a value.
  455. if (empty($filter->value)) {
  456. continue;
  457. }
  458. $operator = $filter->operator;
  459. if ($operator == 'in') {
  460. $filtered_bundles = array_intersect($filtered_bundles, $filter->value);
  461. }
  462. elseif ($operator == 'not in') {
  463. $filtered_bundles = array_diff($filtered_bundles, $filter->value);
  464. }
  465. }
  466. }
  467. foreach ($info['bundles'] as $bundle_name => $bundle) {
  468. // The view is limited to specific bundles, but this bundle isn't one of
  469. // them. Ignore it.
  470. if (!in_array($bundle_name, $filtered_bundles)) {
  471. continue;
  472. }
  473. $instances = field_info_instances($entity_type, $bundle_name);
  474. // Ignore bundles that don't have any field instances attached.
  475. if (empty($instances)) {
  476. continue;
  477. }
  478. $has_enabled_fields = FALSE;
  479. foreach ($display_values as $key) {
  480. if (strpos($key, $bundle_name . '::') !== FALSE) {
  481. $has_enabled_fields = TRUE;
  482. }
  483. }
  484. // The admin has either specified that all values should be modifiable, or
  485. // selected at least one field belonging to this bundle.
  486. if (!empty($display_values[VBO_MODIFY_ACTION_ALL]) || $has_enabled_fields) {
  487. $bundles[$bundle_name] = $bundle;
  488. }
  489. }
  490. return $bundles;
  491. }
  492. /**
  493. * Helper function that recursively strips #required from field widgets.
  494. */
  495. function _views_bulk_operations_modify_action_unset_required(&$element) {
  496. unset($element['#required']);
  497. foreach (element_children($element) as $key) {
  498. _views_bulk_operations_modify_action_unset_required($element[$key]);
  499. }
  500. }
  501. /**
  502. * VBO settings form function.
  503. */
  504. function views_bulk_operations_modify_action_views_bulk_operations_form_options() {
  505. $options['show_all_tokens'] = TRUE;
  506. $options['display_values'] = array(VBO_MODIFY_ACTION_ALL);
  507. return $options;
  508. }
  509. /**
  510. * The settings form for this action.
  511. */
  512. function views_bulk_operations_modify_action_views_bulk_operations_form($options, $entity_type, $dom_id) {
  513. // Initialize default values.
  514. if (empty($options)) {
  515. $options = views_bulk_operations_modify_action_views_bulk_operations_form_options();
  516. }
  517. $form['show_all_tokens'] = array(
  518. '#type' => 'checkbox',
  519. '#title' => t('Show available tokens'),
  520. '#description' => t('Check this to show a list of all available tokens in the bottom of the form. Requires the token module.'),
  521. '#default_value' => $options['show_all_tokens'],
  522. );
  523. $info = entity_get_info($entity_type);
  524. $properties = _views_bulk_operations_modify_action_get_properties($entity_type);
  525. $values = array(VBO_MODIFY_ACTION_ALL => t('- All -'));
  526. foreach ($properties as $key => $property) {
  527. $label = t('Properties');
  528. $values[$label][$key] = $property['label'];
  529. }
  530. foreach ($info['bundles'] as $bundle_name => $bundle) {
  531. $bundle_key = $info['entity keys']['bundle'];
  532. // Show the more detailed label only if the entity type has multiple bundles.
  533. // Otherwise, it would just be confusing.
  534. if (count($info['bundles']) > 1) {
  535. $label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
  536. }
  537. else {
  538. $label = t('Fields');
  539. }
  540. $instances = field_info_instances($entity_type, $bundle_name);
  541. foreach ($instances as $field_name => $field) {
  542. $values[$label][$bundle_name . '::' . $field_name] = $field['label'];
  543. }
  544. }
  545. $form['display_values'] = array(
  546. '#type' => 'select',
  547. '#title' => t('Display values'),
  548. '#options' => $values,
  549. '#multiple' => TRUE,
  550. '#description' => t('Select which values the action form should present to the user.'),
  551. '#default_value' => $options['display_values'],
  552. '#size' => 10,
  553. );
  554. return $form;
  555. }