options.views.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @file
  4. * Provide Views data for options.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. use Drupal\field\FieldStorageConfigInterface;
  9. /**
  10. * Implements hook_field_views_data().
  11. *
  12. * Views integration for list fields. Have a different filter handler and
  13. * argument handlers for list fields. This should allow to select values of
  14. * the list.
  15. */
  16. function options_field_views_data(FieldStorageConfigInterface $field) {
  17. $data = views_field_default_views_data($field);
  18. foreach ($data as $table_name => $table_data) {
  19. foreach ($table_data as $field_name => $field_data) {
  20. if (isset($field_data['filter']) && $field_name != 'delta') {
  21. $data[$table_name][$field_name]['filter']['id'] = 'list_field';
  22. }
  23. if (isset($field_data['argument']) && $field_name != 'delta') {
  24. if ($field->getType() == 'list_string') {
  25. $data[$table_name][$field_name]['argument']['id'] = 'string_list_field';
  26. }
  27. else {
  28. $data[$table_name][$field_name]['argument']['id'] = 'number_list_field';
  29. }
  30. }
  31. }
  32. }
  33. return $data;
  34. }