You are here

commerce_coupon_batch.module in Commerce coupon batch 7

Same filename and directory in other branches
  1. 7.2 commerce_coupon_batch.module

Batch generation functionalities for commerce_coupon module.

File

commerce_coupon_batch.module
View source
<?php

/**
 * @file
 * Batch generation functionalities for commerce_coupon module.
 */

/**
 * Implements hook_menu().
 */
function commerce_coupon_batch_menu() {
  $items['admin/commerce/coupons/batch'] = array(
    'title' => 'Batch create coupons',
    'page callback' => 'commerce_coupon_batch_overview_page',
    'access arguments' => array(
      'commerce coupon batch creation',
    ),
  );
  $coupon_types = commerce_coupon_get_types();
  foreach ($coupon_types as $type => $info) {
    $entity = commerce_coupon_create($type);
    $type_arg = strtr($type, '_', '-');
    $items['admin/commerce/coupons/batch/' . $type_arg] = array(
      'tab_parent' => 'admin/commerce/coupons/batch',
      'title' => 'Batch create @name',
      'title arguments' => array(
        '@name' => $info->label,
      ),
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'commerce_coupon_batch_form',
        $entity,
      ),
      'file' => 'includes/commerce_coupon_batch.form.inc',
      'access callback' => 'commerce_coupon_access',
      'access arguments' => array(
        'create',
        $entity,
      ),
    );
    $items['admin/commerce/coupons/batch/' . $type_arg . '/generate'] = array(
      'title' => 'Edit',
      'access callback' => 'commerce_coupon_access',
      'access arguments' => array(
        'create',
        $entity,
      ),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    );
  }
  return $items;
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function commerce_coupon_batch_menu_local_tasks_alter(&$data, $router_item, $root_path) {

  // Add action link 'admin/commerce/coupons/batch' on 'admin/commerce/coupons'.
  if ($root_path == 'admin/commerce/coupons') {
    $item = menu_get_item('admin/commerce/coupons/batch');
    if ($item['access']) {
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
    }
  }
}

/**
 * Implements hook_permission().
 */
function commerce_coupon_batch_permission() {
  $permissions['commerce coupon batch creation'] = array(
    'title' => t('Commerce Coupon Batch Creation'),
    'description' => t('Allows users to create coupons by a batch.'),
  );
  return $permissions;
}

/**
 * Display the coupon type overview page for batch creation if there's more than
 * one coupon type.
 */
function commerce_coupon_batch_overview_page() {
  $item = menu_get_item();
  $content = system_admin_menu_block($item);

  // Bypass the node/add listing if only one content type is available.
  if (count($content) == 1) {
    $item = array_shift($content);
    drupal_goto($item['href']);
  }
  return theme('admin_block_content', array(
    'content' => $content,
  ));
}

Functions

Namesort descending Description
commerce_coupon_batch_menu Implements hook_menu().
commerce_coupon_batch_menu_local_tasks_alter Implements hook_menu_local_tasks_alter().
commerce_coupon_batch_overview_page Display the coupon type overview page for batch creation if there's more than one coupon type.
commerce_coupon_batch_permission Implements hook_permission().