You are here

function commerce_shipping_ui_menu in Commerce Shipping 7.2

Same name and namespace in other branches
  1. 7 commerce_shipping_ui.module \commerce_shipping_ui_menu()

Implements hook_menu().

File

./commerce_shipping_ui.module, line 11
Default Shipping UI for Drupal Commerce.

Code

function commerce_shipping_ui_menu() {
  $items = array();
  $items['admin/commerce/config/shipping/methods'] = array(
    'title' => 'Shipping methods',
    'description' => 'Manage shipping methods.',
    'page callback' => 'commerce_shipping_ui_overview',
    'page arguments' => array(
      'methods',
    ),
    'access arguments' => array(
      'administer shipping',
    ),
    'weight' => 5,
    'type' => MENU_LOCAL_TASK,
    'file' => 'includes/commerce_shipping_ui.admin.inc',
  );
  $shipping_methods = commerce_shipping_methods();
  foreach ($shipping_methods as $name => $shipping_method) {

    // Convert underscores to hyphens for the menu item argument.
    $name_arg = strtr($name, '_', '-');
    $items['admin/commerce/config/shipping/methods/' . $name_arg] = array(
      'title callback' => 'commerce_shipping_method_get_title',
      'title arguments' => array(
        $name,
      ),
      'description' => 'Redirect to the shipping method list.',
      'page callback' => 'drupal_goto',
      'page arguments' => array(
        'admin/commerce/config/shipping/methods',
      ),
      'access arguments' => array(
        'administer shipping',
      ),
    );
    if (rules_config_load('commerce_shipping_method_' . $name)) {
      $items['admin/commerce/config/shipping/methods/' . $name_arg . '/rule'] = array(
        'title' => 'Configure rule',
        'description' => 'Add conditions to the rule used to collect rates for this shipping method.',
        'page callback' => 'drupal_goto',
        'page arguments' => array(
          'admin/config/workflow/rules/reaction/manage/commerce_shipping_method_' . $name,
        ),
        'access arguments' => array(
          'administer rules',
        ),
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_INLINE,
        'weight' => 5,
      );
    }
    $items['admin/commerce/config/shipping/methods/' . $name_arg . '/services'] = array(
      'title' => 'View services',
      'description' => 'View the table of services defined for this shipping method.',
      'page callback' => 'drupal_goto',
      'page arguments' => array(
        'admin/commerce/config/shipping/services/' . $name_arg,
      ),
      'access arguments' => array(
        'administer shipping',
      ),
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_INLINE,
      'weight' => 10,
    );
  }
  if (!empty($shipping_methods)) {
    reset($shipping_methods);
    $default_method = key($shipping_methods);
  }
  else {
    $default_method = NULL;
  }
  $items['admin/commerce/config/shipping'] = array(
    'title' => 'Shipping',
    'description' => 'Manage shipping methods and services.',
    'page callback' => 'commerce_shipping_ui_overview',
    'page arguments' => array(
      'services',
      $default_method,
    ),
    'access arguments' => array(
      'administer shipping',
    ),
    'file' => 'includes/commerce_shipping_ui.admin.inc',
  );
  $items['admin/commerce/config/shipping/services'] = array(
    'title' => 'Shipping services',
    'description' => 'Manage shipping services.',
    'weight' => 0,
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  foreach ($shipping_methods as $method_name => $shipping_method) {

    // Convert underscores to hyphens for the menu item argument.
    $method_name_arg = strtr($method_name, '_', '-');
    $items['admin/commerce/config/shipping/services/' . $method_name_arg] = array(
      'title' => $shipping_method['title'],
      'description' => 'Manage shipping services for this shipping method.',
      'page callback' => 'commerce_shipping_ui_overview',
      'page arguments' => array(
        'services',
        $method_name,
      ),
      'access arguments' => array(
        'administer shipping',
      ),
      'type' => $default_method == $method_name ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
      'file' => 'includes/commerce_shipping_ui.admin.inc',
    );
    foreach (commerce_shipping_services($method_name) as $service_name => $shipping_service) {

      // Convert underscores to hyphens for the menu item argument.
      $service_name_arg = $method_name_arg . '-' . strtr($service_name, '_', '-');
      $items['admin/commerce/config/shipping/services/' . $service_name_arg] = array(
        'title callback' => 'commerce_shipping_service_get_title',
        'title arguments' => array(
          (string) $service_name,
        ),
        'description' => 'Redirect to the shipping service list.',
        'page callback' => 'drupal_goto',
        'page arguments' => array(
          'admin/commerce/config/shipping/services/' . $method_name_arg,
        ),
        'access arguments' => array(
          'administer shipping',
        ),
      );
      if (rules_config_load('commerce_shipping_service_' . $service_name)) {
        $items['admin/commerce/config/shipping/services/' . $service_name_arg . '/component'] = array(
          'title' => 'Configure component',
          'description' => 'Add conditions to the Rules component used to rate orders for this service.',
          'page callback' => 'drupal_goto',
          'page arguments' => array(
            'admin/config/workflow/rules/components/manage/commerce_shipping_service_' . $service_name,
          ),
          'access arguments' => array(
            'administer rules',
          ),
          'type' => MENU_LOCAL_TASK,
          'context' => MENU_CONTEXT_INLINE,
          'weight' => 5,
        );
      }
    }
  }
  $items['admin/commerce/config/shipping/calculation-rules'] = array(
    'title' => 'Calculation rules',
    'description' => 'Add and configure your shipping rate calculation rules.',
    'page callback' => 'commerce_shipping_ui_rate_calculation_rules',
    'access arguments' => array(
      'administer shipping',
    ),
    'weight' => 10,
    'type' => MENU_LOCAL_TASK,
    'file' => 'includes/commerce_shipping_ui.admin.inc',
  );

  // Add the menu items for the various Rules forms.
  $controller = new RulesUIController();
  $items += $controller
    ->config_menu('admin/commerce/config/shipping/calculation-rules');
  $items['admin/commerce/config/shipping/calculation-rules/add'] = array(
    'title' => 'Add a calculation rule',
    'description' => 'Adds an additional shipping rate calculation rule configuration.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'commerce_shipping_ui_add_calculation_rule_form',
      'admin/commerce/config/shipping/calculation-rules',
    ),
    'access arguments' => array(
      'administer shipping',
    ),
    'file path' => drupal_get_path('module', 'rules_admin'),
    'file' => 'rules_admin.inc',
  );
  return $items;
}