field_collection.admin.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @file
  4. * Provides the field_collection module admin pages.
  5. */
  6. /**
  7. * Menu callback; list all field collections on this site.
  8. */
  9. function field_collections_overview() {
  10. $instances = field_info_instances();
  11. $field_types = field_info_field_types();
  12. $bundles = field_info_bundles();
  13. $header = array(t('Field name'), t('Used in'), array('data' => t('Operations'), 'colspan' => '2'));
  14. $rows = array();
  15. foreach ($instances as $entity_type => $type_bundles) {
  16. foreach ($type_bundles as $bundle => $bundle_instances) {
  17. foreach ($bundle_instances as $field_name => $instance) {
  18. $field = field_info_field($field_name);
  19. if ($field['type'] == 'field_collection') {
  20. $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
  21. $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');
  22. $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;
  23. $rows[$field_name]['data'][1][] = l($bundles[$entity_type][$bundle]['label'], $admin_path . '/fields');
  24. }
  25. }
  26. }
  27. }
  28. foreach ($rows as $field_name => $cell) {
  29. $rows[$field_name]['data'][1] = implode(', ', $cell['data'][1]);
  30. $field_name_url_str = strtr($field_name, array('_' => '-'));
  31. $rows[$field_name]['data'][2] = l(t('manage fields'), 'admin/structure/field-collections/' . $field_name_url_str . '/fields');
  32. $rows[$field_name]['data'][3] = l(t('manage display'), 'admin/structure/field-collections/' . $field_name_url_str . '/display');
  33. }
  34. if (empty($rows)) {
  35. $output = t('No field collections have been defined yet. To do so attach a field collection field to any entity.');
  36. }
  37. else {
  38. // Sort rows by field name.
  39. ksort($rows);
  40. $output = theme('table', array('header' => $header, 'rows' => $rows));
  41. }
  42. return $output;
  43. }