styles_ui.module 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * Allows administration of the Styles modules.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function styles_ui_menu() {
  10. // Each field type Style may choose to allow the Styles module to manage its
  11. // UI. To do so, they'll need to create an 'admin' array in its definition
  12. // at hook_styles_containers that will contain the path info:
  13. // 'path' => The path to the overview listing page,
  14. // 'title' => The title for the overview listing page,
  15. // 'description' => The description for the overview listing page,
  16. // 'access arguments' => The access arguments for the overview listing page,
  17. // 'add' => an optional array with the info for adding a new container:
  18. // 'title' => The title to add a new container for this field,
  19. // 'description' => The discription to add a new container for this field,
  20. $items = array();
  21. $styles_containers = styles_default_containers();
  22. foreach ($styles_containers as $field_type => $containers) {
  23. if (isset($containers['admin']) && isset($containers['admin']['path'])) {
  24. $field_info = field_info_field_types($field_type);
  25. $field_label = $field_info['label'];
  26. $title = $field_label . ' styles';
  27. $description = 'Configure ' . $field_label . ' styles.';
  28. $access = isset($containers['admin']['access arguments']) ? $containers['admin']['access arguments'] : array('administer styles ui');
  29. $items[$containers['admin']['path']] = array(
  30. 'title' => $title,
  31. 'description' => $description,
  32. 'access arguments' => $access,
  33. 'page callback' => 'styles_ui_containers_overview',
  34. 'page arguments' => array($field_type),
  35. 'file' => 'styles_ui.admin.inc',
  36. );
  37. $items[$containers['admin']['path'] . '/list'] = array(
  38. 'title' => 'List',
  39. 'type' => MENU_DEFAULT_LOCAL_TASK,
  40. 'weight' => -10,
  41. );
  42. $title = 'Add ' . $field_label . ' style';
  43. $description = '';
  44. $items[$containers['admin']['path'] . '/add'] = array(
  45. 'title' => $title,
  46. 'description' => $description,
  47. 'page callback' => 'drupal_get_form',
  48. 'page arguments' => array('styles_ui_style_add_form', $field_type),
  49. 'access arguments' => $access,
  50. 'type' => MENU_LOCAL_ACTION,
  51. 'file' => 'styles_ui.admin.inc',
  52. );
  53. $count = substr_count($containers['admin']['path'] . '/edit/%', '/');
  54. $items[$containers['admin']['path'] . '/edit/%'] = array(
  55. 'page callback' => 'drupal_get_form',
  56. 'page arguments' => array('styles_ui_style_edit_form', $field_type, $count),
  57. 'access arguments' => $access,
  58. 'file' => 'styles_ui.admin.inc',
  59. );
  60. $items[$containers['admin']['path'] . '/delete/%'] = array(
  61. 'page callback' => 'drupal_get_form',
  62. 'page arguments' => array('styles_ui_delete_confirm', $field_type, $count),
  63. 'access arguments' => $access,
  64. 'file' => 'styles_ui.admin.inc',
  65. );
  66. }
  67. }
  68. $items['styles-ui/preview/%/%/%'] = array(
  69. 'page callback' => 'styles_ui_preview_ajax',
  70. 'page arguments' => array(2, 3, 4),
  71. 'access arguments' => array('access content'),
  72. 'file' => 'styles_ui.admin.inc',
  73. 'type' => MENU_CALLBACK,
  74. );
  75. return $items;
  76. }
  77. /**
  78. * Implement Styles module's hook_styles_style_flush().
  79. */
  80. function styles_ui_styles_style_flush($style = NULL) {
  81. // Rebuild the menu so that we catch any new styles or containers.
  82. menu_rebuild();
  83. }
  84. /**
  85. * Implementation of hook_permission().
  86. */
  87. function styles_ui_permission() {
  88. return array(
  89. 'administer styles ui' => array(
  90. 'title' => t('Administer Styles'),
  91. 'description' => t('Configure styles settings.'),
  92. ),
  93. );
  94. }