Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @fle
- * Module file for adding a tab to edit the node's product page.
- */
- /**
- * Implements hook_menu().
- */
- function commerce_edit_product_menu() {
- $items = array();
- $items['node/%node/edit-product'] = array(
- 'title' => t('Edit Product'),
- 'access callback' => 'commerce_edit_product_callback',
- 'access arguments' => array(1),
- 'type' => MENU_LOCAL_TASK,
- 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
- );
- return $items;
- }
- /**
- * Implements hook_menu_local_tasks_alter().
- *
- * Chaging the tab href and not call to other function and then use drupl_goto.
- */
- function commerce_edit_product_menu_local_tasks_alter(&$data, $router_item, $root_path) {
- foreach ($data['tabs'][0]['output'] as $key => $item) {
- if ($item['#link']['path'] == "node/%/edit-product") {
- $wrapper = entity_metadata_wrapper('node', $router_item['page_arguments'][0]);
- $data['tabs'][0]['output'][$key]['#link']['href'] = 'admin/commerce/products/' . $wrapper->field_product->getIdentifier() . '/edit';
- }
- }
- }
- /**
- * Access callback.
- *
- * @param $node
- * The node object.
- *
- * @return
- * TRUE/FALSE if the user can edit the product.
- */
- function commerce_edit_product_callback($node) {
- global $user;
- if (!$user->uid || ($node->uid != $user->uid)) {
- return;
- }
- $edit_commerce_product = user_access('edit any commerce_product entity of bundle product');
- $edit_any_commerce_product = user_access('edit own commerce_product entities of bundle product');
- return $edit_commerce_product | $edit_any_commerce_product;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement