You are here

function uc_attribute_menu in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.module \uc_attribute_menu()
  2. 7.3 uc_attribute/uc_attribute.module \uc_attribute_menu()

Implementation of hook_menu().

File

uc_attribute/uc_attribute.module, line 52

Code

function uc_attribute_menu($may_cache) {
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/store/products/attributes',
      'title' => t('Manage attributes'),
      'description' => t('Create and edit attributes and options.'),
      'access' => user_access('administer attributes'),
      'callback' => 'uc_attribute_admin',
      'type' => MENU_NORMAL_ITEM,
      'weight' => -1,
    );
    $items[] = array(
      'path' => 'admin/store/products/attributes/overview',
      'title' => t('Overview'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => 0,
    );
    $items[] = array(
      'path' => 'admin/store/products/attributes/add',
      'title' => t('Add an attribute'),
      'access' => user_access('administer attributes'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'uc_attribute_form',
      ),
      'type' => MENU_LOCAL_TASK,
      'weight' => 5,
    );
    $items[] = array(
      'path' => 'admin/store/settings/attributes',
      'title' => t('Attribute settings'),
      'description' => t('Configure the attribute settings'),
      'access' => user_access('administer attributes'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'uc_attribute_admin_settings',
      ),
      'type' => MENU_NORMAL_ITEM,
    );
  }
  else {
    if (intval(arg(4)) > 0) {
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/edit',
        'title' => t('Edit attribute'),
        'access' => user_access('administer attributes'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'uc_attribute_form',
          arg(4),
        ),
        'type' => MENU_CALLBACK,
      );
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/delete',
        'access' => user_access('administer attributes'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'uc_attribute_delete_confirm',
          arg(4),
        ),
        'type' => MENU_CALLBACK,
      );
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/options',
        'title' => t('Options'),
        'access' => user_access('administer attributes'),
        'callback' => 'uc_attribute_options',
        'callback arguments' => array(
          arg(4),
        ),
        'type' => MENU_CALLBACK,
      );
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/options/overview',
        'title' => t('Overview'),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => 0,
      );
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/options/add',
        'title' => t('Add an option'),
        'access' => user_access('administer attributes'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'uc_attribute_option_form',
          arg(4),
          NULL,
        ),
        'type' => MENU_LOCAL_TASK,
        'weight' => 5,
      );
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/options/' . arg(6) . '/edit',
        'title' => t('Edit option'),
        'access' => user_access('administer attributes'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'uc_attribute_option_form',
          arg(4),
          arg(6),
        ),
        'type' => MENU_CALLBACK,
      );
      $items[] = array(
        'path' => 'admin/store/products/attributes/' . arg(4) . '/options/' . arg(6) . '/delete',
        'title' => t('Delete option'),
        'access' => user_access('administer attributes'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'uc_attribute_option_delete_confirm',
          arg(4),
          arg(6),
        ),
        'type' => MENU_CALLBACK,
      );
    }

    // Menu items for default product class attributes and options.
    $items[] = array(
      'path' => 'admin/store/products/classes/' . arg(4) . '/attributes',
      'title' => t('Attributes'),
      'access' => uc_attribute_product_class_access(),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'uc_object_attributes_form',
        arg(4),
        'class',
      ),
      'weight' => 1,
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/store/products/classes/' . arg(4) . '/options',
      'title' => t('Options'),
      'access' => uc_attribute_product_class_access(),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'uc_object_options_form',
        arg(4),
        'class',
      ),
      'weight' => 2,
      'type' => MENU_LOCAL_TASK,
    );

    // Insert subitems into the edit node page for product types.
    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
      $node = node_load(arg(1));
      if ($node->nid && in_array($node->type, module_invoke_all('product_types'))) {
        $items[] = array(
          'path' => 'node/' . arg(1) . '/edit/attributes',
          'title' => t('Attributes'),
          'access' => uc_attribute_product_access(arg(1)),
          'callback' => 'drupal_get_form',
          'callback arguments' => array(
            'uc_object_attributes_form',
            arg(1),
            'product',
            'overview',
          ),
          'weight' => 1,
          'type' => MENU_LOCAL_TASK,
        );
        $items[] = array(
          'path' => 'node/' . arg(1) . '/edit/attributes/add',
          'title' => t('Attributes'),
          'access' => uc_attribute_product_access(arg(1)),
          'callback' => 'drupal_get_form',
          'callback arguments' => array(
            'uc_object_attributes_form',
            arg(1),
            'product',
            'add',
          ),
          'weight' => 1,
          'type' => MENU_LOCAL_TASK,
        );
        $items[] = array(
          'path' => 'node/' . arg(1) . '/edit/options',
          'title' => t('Options'),
          'access' => uc_attribute_product_option_access(arg(1)),
          'callback' => 'drupal_get_form',
          'callback arguments' => array(
            'uc_object_options_form',
            arg(1),
            'product',
          ),
          'weight' => 2,
          'type' => MENU_LOCAL_TASK,
        );
        $items[] = array(
          'path' => 'node/' . arg(1) . '/edit/adjustments',
          'title' => t('Adjustments'),
          'access' => uc_attribute_product_option_access(arg(1)),
          'callback' => 'drupal_get_form',
          'callback arguments' => array(
            'uc_product_adjustments_form',
            arg(1),
          ),
          'weight' => 3,
          'type' => MENU_LOCAL_TASK,
        );
      }
    }
    drupal_add_css(drupal_get_path('module', 'uc_attribute') . '/uc_attribute.css');
  }
  return $items;
}