name.diff.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Provide diff field functions for the Name Field module.
  5. */
  6. /**
  7. * Diff field callback for parsing name field comparative values.
  8. */
  9. function name_field_diff_view($items, $context) {
  10. $field = $context['field'];
  11. $instance = $context['instance'];
  12. $settings = $context['settings'];
  13. $diff_items = array();
  14. $format = name_get_format_by_machine_name($settings['format']);
  15. if (empty($format)) {
  16. $format = name_get_format_by_machine_name('default');
  17. }
  18. foreach ($items as $delta => $item) {
  19. $name = name_format($item, $format);
  20. $diff_items[$delta] = _name_value_sanitize($name, NULL, $settings['output']);
  21. }
  22. return $diff_items;
  23. }
  24. /**
  25. * Provide default field comparison options.
  26. */
  27. function name_field_diff_default_options($field_type) {
  28. return array(
  29. 'format' => 'default',
  30. 'output' => 'default',
  31. );
  32. }
  33. /**
  34. * Provide a form for setting the field comparison options.
  35. */
  36. function name_field_diff_options_form($field_type, $settings) {
  37. $options_form = array();
  38. $formats = array(
  39. 'default' => t('Default'),
  40. ) + name_get_custom_format_options();
  41. $options_form['format'] = array(
  42. '#type' => 'select',
  43. '#title' => t('Name format'),
  44. '#default_value' => $settings['format'],
  45. '#options' => $formats,
  46. '#required' => TRUE,
  47. );
  48. $options_form['output'] = array(
  49. '#type' => 'radios',
  50. '#title' => t('Output'),
  51. '#default_value' => $settings['output'],
  52. '#options' => _name_formatter_output_options(),
  53. '#description' => t('This option provides additional options for rendering the field.'),
  54. '#required' => TRUE,
  55. );
  56. return $options_form;
  57. }