You are here

function commerce_coupon_ui_menu in Commerce Coupon 7

Implements hook_menu().

File

./commerce_coupon_ui.module, line 27
Coupon User Interface for Drupal Commerce

Code

function commerce_coupon_ui_menu() {
  $items['admin/commerce/coupons/add'] = array(
    'title' => 'Create Coupon',
    'description' => 'Create a new coupon',
    'page callback' => 'commerce_coupon_ui_add_page',
    'weight' => 10,
    'access callback' => 'commerce_coupon_ui_coupon_add_any_access',
  );
  foreach (commerce_coupon_get_types() as $type => $coupon_type) {
    if (!empty($coupon_type->status)) {
      $items['admin/commerce/coupons/add/' . strtr($type, array(
        '_' => '-',
      ))] = array(
        'title' => 'Create !name',
        'title arguments' => array(
          '!name' => $coupon_type->label,
        ),
        'page callback' => 'commerce_coupon_ui_coupon_form_wrapper',
        'page arguments' => array(
          commerce_coupon_create($type),
          'add',
        ),
        'access callback' => 'commerce_coupon_access',
        'access arguments' => array(
          'create',
          commerce_coupon_create($type),
        ),
      );
    }
  }

  // Edit & Delete coupon forms.
  $items['admin/commerce/coupons/%commerce_coupon'] = array(
    'title' => 'Edit',
    'page callback' => 'commerce_coupon_ui_coupon_form_wrapper',
    'page arguments' => array(
      3,
      'edit',
    ),
    'access callback' => 'commerce_coupon_access',
    'access arguments' => array(
      'update',
      3,
    ),
    'weight' => 0,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items['admin/commerce/coupons/%commerce_coupon/edit'] = array(
    'title' => 'Edit',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items['admin/commerce/coupons/%commerce_coupon/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'commerce_coupon_ui_coupon_delete_form_wrapper',
    'page arguments' => array(
      3,
    ),
    'access callback' => 'commerce_coupon_access',
    'access arguments' => array(
      'update',
      3,
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 20,
    'context' => MENU_CONTEXT_INLINE,
  );

  // Coupon types.
  $items['admin/commerce/coupons/types'] = array(
    'title' => 'Coupon types',
    'description' => 'Manage coupon types for your store.',
    'page callback' => 'commerce_coupon_ui_types_overview',
    'access arguments' => array(
      'administer coupon types',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 0,
  );
  $items['admin/commerce/coupons/types/add'] = array(
    'title' => 'Add coupon type',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'commerce_coupon_ui_type_form',
      commerce_coupon_type_create(),
    ),
    'access arguments' => array(
      'administer coupon types',
    ),
    'type' => MENU_LOCAL_ACTION,
    'file' => 'includes/commerce_coupon_ui.forms.inc',
  );
  foreach (commerce_coupon_get_types() as $type => $coupon_type) {
    if (!empty($coupon_type->status)) {

      // Convert underscores to hyphens for the menu item argument.
      $type_arg = strtr($type, '_', '-');
      $items['admin/commerce/coupons/types/' . $type_arg] = array(
        'title' => $coupon_type->label,
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'commerce_coupon_ui_type_form',
          $coupon_type,
        ),
        'access arguments' => array(
          'administer coupon types',
        ),
        'file' => 'includes/commerce_coupon_ui.forms.inc',
      );
      $items['admin/commerce/coupons/types/' . $type_arg . '/edit'] = array(
        'title' => 'Edit',
        'access arguments' => array(
          'administer coupon types',
        ),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
      );
      $items['admin/commerce/coupons/types/' . $type_arg . '/delete'] = array(
        'title' => 'Delete',
        'page callback' => 'commerce_coupon_ui_coupon_type_delete_form_wrapper',
        'page arguments' => array(
          $coupon_type,
        ),
        'access arguments' => array(
          'administer coupon types',
        ),
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_INLINE,
        'weight' => 10,
      );
    }
  }

  // Add a general settings form.
  $items['admin/commerce/coupons/settings'] = array(
    'title' => 'Settings',
    'description' => 'Global configuration for coupons.',
    'file' => 'includes/commerce_coupon_ui.settings.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'commerce_coupon_ui_settings_form',
    ),
    'access arguments' => array(
      'administer coupon settings',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 50,
  );

  // Remove coupon from order.
  $items['commerce/coupons/order/remove/%commerce_coupon/%commerce_order'] = array(
    'title' => 'Delete from order',
    'page callback' => 'commerce_coupon_ui_coupon_remove_coupon_from_order',
    'page arguments' => array(
      4,
      5,
    ),
    'access arguments' => array(
      'access checkout',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}