commerce_line_item_ui.module

Tracking 7.x-1.x branch
  1. drupal
    1. 7 contributions/commerce/modules/line_item/commerce_line_item_ui.module

Provides the user interface for managing Line Item types.

Functions & methods

NameDescription
commerce_line_item_ui_entity_info_alterImplements hook_entity_info_alter().
commerce_line_item_ui_form_alterImplements hook_form_alter().
commerce_line_item_ui_form_entity_translation_admin_form_alterImplements hook_form_FORM_ID_alter().
commerce_line_item_ui_helpImplements hook_help().
commerce_line_item_ui_line_item_type_redirectRedirects a line item type URL to its fields management page.
commerce_line_item_ui_menuImplements hook_menu().
commerce_line_item_ui_menu_alterImplements hook_menu_alter().
commerce_line_item_ui_themeImplements hook_theme().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Provides the user interface for managing Line Item types.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function commerce_line_item_ui_menu() {
  10. $items = array();
  11. $items['admin/commerce/config/line-items'] = array(
  12. 'title' => 'Line item types',
  13. 'description' => 'Manage line item types for your store.',
  14. 'page callback' => 'commerce_line_item_ui_types_overview',
  15. 'access arguments' => array('administer line item types'),
  16. 'file' => 'includes/commerce_line_item_ui.types.inc',
  17. );
  18. foreach (commerce_line_item_types() as $type => $line_item_type) {
  19. // Convert underscores to hyphens for the menu item argument.
  20. $type_arg = strtr($type, '_', '-');
  21. $items['admin/commerce/config/line-items/' . $type_arg] = array(
  22. 'title' => $line_item_type['name'],
  23. 'page callback' => 'commerce_line_item_ui_line_item_type_redirect',
  24. 'page arguments' => array($type_arg),
  25. 'access arguments' => array('administer line item types'),
  26. );
  27. }
  28. return $items;
  29. }
  30. /**
  31. * Redirects a line item type URL to its fields management page.
  32. */
  33. function commerce_line_item_ui_line_item_type_redirect($type) {
  34. drupal_goto('admin/commerce/config/line-items/' . $type . '/fields');
  35. }
  36. /**
  37. * Implements hook_menu_alter().
  38. */
  39. function commerce_line_item_ui_menu_alter(&$items) {
  40. // Transform the field UI tabs into contextual links.
  41. foreach (commerce_line_item_types() as $type => $line_item_type) {
  42. // Convert underscores to hyphens for the menu item argument.
  43. $type_arg = strtr($type, '_', '-');
  44. $items['admin/commerce/config/line-items/' . $type_arg . '/fields']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
  45. $items['admin/commerce/config/line-items/' . $type_arg . '/display']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
  46. }
  47. }
  48. /**
  49. * Implements hook_theme().
  50. */
  51. function commerce_line_item_ui_theme() {
  52. return array(
  53. 'line_item_type_admin_overview' => array(
  54. 'variables' => array('type' => NULL),
  55. 'file' => 'includes/commerce_line_item_ui.types.inc',
  56. ),
  57. );
  58. }
  59. /**
  60. * Implements hook_entity_info_alter().
  61. *
  62. * Expose the admin UI for line item fields.
  63. */
  64. function commerce_line_item_ui_entity_info_alter(&$entity_info) {
  65. foreach ($entity_info['commerce_line_item']['bundles'] as $type => &$bundle) {
  66. $bundle['admin'] = array(
  67. 'path' => 'admin/commerce/config/line-items/' . strtr($type, '_', '-'),
  68. 'access arguments' => array('administer line item types'),
  69. );
  70. }
  71. }
  72. /**
  73. * Implements hook_form_alter().
  74. */
  75. function commerce_line_item_ui_form_alter(&$form, &$form_state, $form_id) {
  76. // On field administration forms for line item types set the title.
  77. if (in_array($form_id, array('field_ui_field_overview_form', 'field_ui_display_overview_form'))) {
  78. if ($form['#entity_type'] == 'commerce_line_item') {
  79. // Load the line item type being modified for this form.
  80. $line_item_type = commerce_line_item_type_load($form['#bundle']);
  81. drupal_set_title($line_item_type['name']);
  82. }
  83. }
  84. }
  85. /**
  86. * Implements hook_form_FORM_ID_alter().
  87. */
  88. function commerce_line_item_ui_form_entity_translation_admin_form_alter(&$form, &$form_state, $form_id) {
  89. // Hide the commerce_line_item option from entity translation.
  90. unset($form['entity_translation_entity_types']['#options']['commerce_line_item']);
  91. }
  92. /**
  93. * Implements hook_help().
  94. */
  95. function commerce_line_item_ui_help($path, $arg) {
  96. switch ($path) {
  97. case 'admin/commerce/config/line-items':
  98. return '<p>' . t('Line items represent anything on an order that affects the order total. Each line item must be of one of the line item types listed below, which define how these items interact with Add to Cart forms, the shopping cart, the order edit page, and more. Line item types are defined by modules, with some modules also allowing you to clone line item types through this interface.') . '</p>';
  99. }
  100. }
  101. /**
  102. * Implements hook_views_api().
  103. *
  104. function commerce_line_item_ui_views_api() {
  105. return array(
  106. 'api' => 3,
  107. 'path' => drupal_get_path('module', 'commerce_line_item_ui') . '/includes/views',
  108. );
  109. }*/