Projet

Général

Profil

Paste
Télécharger (3,84 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / line_item / commerce_line_item_ui.module @ b858700c

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides the user interface for managing Line Item types.
6
 */
7

    
8
/**
9
 * Implements hook_menu().
10
 */
11
function commerce_line_item_ui_menu() {
12
  $items = array();
13

    
14
  $items['admin/commerce/config/line-items'] = array(
15
    'title' => 'Line item types',
16
    'description' => 'Manage line item types for your store.',
17
    'page callback' => 'commerce_line_item_ui_types_overview',
18
    'access arguments' => array('administer line item types'),
19
    'file' => 'includes/commerce_line_item_ui.types.inc',
20
  );
21

    
22
  foreach (commerce_line_item_types() as $type => $line_item_type) {
23
    // Convert underscores to hyphens for the menu item argument.
24
    $type_arg = strtr($type, '_', '-');
25

    
26
    $items['admin/commerce/config/line-items/' . $type_arg] = array(
27
      'title' => $line_item_type['name'],
28
      'page callback' => 'commerce_line_item_ui_line_item_type_redirect',
29
      'page arguments' => array($type_arg),
30
      'access arguments' => array('administer line item types'),
31
    );
32
  }
33

    
34
  return $items;
35
}
36

    
37
/**
38
 * Redirects a line item type URL to its fields management page.
39
 */
40
function commerce_line_item_ui_line_item_type_redirect($type) {
41
  drupal_goto('admin/commerce/config/line-items/' . $type . '/fields');
42
}
43

    
44
/**
45
 * Implements hook_menu_alter().
46
 */
47
function commerce_line_item_ui_menu_alter(&$items) {
48
  // Transform the field UI tabs into contextual links.
49
  foreach (commerce_line_item_types() as $type => $line_item_type) {
50
    // Convert underscores to hyphens for the menu item argument.
51
    $type_arg = strtr($type, '_', '-');
52
    $items['admin/commerce/config/line-items/' . $type_arg . '/fields']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
53
    $items['admin/commerce/config/line-items/' . $type_arg . '/display']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
54
  }
55
}
56

    
57
/**
58
 * Implements hook_theme().
59
 */
60
function commerce_line_item_ui_theme() {
61
  return array(
62
    'line_item_type_admin_overview' => array(
63
      'variables' => array('type' => NULL),
64
      'file' => 'includes/commerce_line_item_ui.types.inc',
65
    ),
66
  );
67
}
68

    
69
/**
70
 * Implements hook_entity_info_alter().
71
 *
72
 * Expose the admin UI for line item fields.
73
 */
74
function commerce_line_item_ui_entity_info_alter(&$entity_info) {
75
  foreach ($entity_info['commerce_line_item']['bundles'] as $type => &$bundle) {
76
    $bundle['admin'] = array(
77
      'path' => 'admin/commerce/config/line-items/' . strtr($type, '_', '-'),
78
      'access arguments' => array('administer line item types'),
79
    );
80
  }
81
}
82

    
83
/**
84
 * Implements hook_form_alter().
85
 */
86
function commerce_line_item_ui_form_alter(&$form, &$form_state, $form_id) {
87
  // On field administration forms for line item types set the title.
88
  if (in_array($form_id, array('field_ui_field_overview_form', 'field_ui_display_overview_form'))) {
89
    if ($form['#entity_type'] == 'commerce_line_item') {
90
      // Load the line item type being modified for this form.
91
      $line_item_type = commerce_line_item_type_load($form['#bundle']);
92

    
93
      drupal_set_title($line_item_type['name']);
94
    }
95
  }
96
}
97

    
98
/**
99
 * Implements hook_form_FORM_ID_alter().
100
 */
101
function commerce_line_item_ui_form_entity_translation_admin_form_alter(&$form, &$form_state, $form_id) {
102
  // Hide the commerce_line_item option from entity translation.
103
  unset($form['entity_translation_entity_types']['#options']['commerce_line_item']);
104
}
105

    
106
/**
107
 * Implements hook_help().
108
 */
109
function commerce_line_item_ui_help($path, $arg) {
110
  switch ($path) {
111
    case 'admin/commerce/config/line-items':
112
      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>';
113
  }
114
}