1

I have a view that lists a content type in a table. There are edit/delete links so the users can edit the content. I want to display these links conditionally.

These are just orders sent in by customers and I only want to let them edit or delete them until the "status" field is set to "processed". Once their order has been processed, they shouldn't be able to modify nor delete it. I can show them a message via a custom module, but it would be nice to remove the edit/delete buttons for these nodes.

3
  • 1
    Use proper access restrictions. Views will not show the link if the user has no access to perform that action (edit/delete/view/etc)
    – AKS
    Apr 20, 2013 at 20:51
  • 1
    +1 for what Ayesh says. If the user has access to edit/delete the node then they can do so regardless of whether you give them a link or not. If you take away the link and they still have the required permissions, they can go back to the node directly and edit or delete it (it will be in their browser history or they might have book marked it - if it is public then google can link to it too).
    – rooby
    Apr 21, 2013 at 2:12
  • The users have rights to edit or delete their own orders. What I want is to revoke this right only on orders that have been processed. Can I set permissions conditionally based on a field of a node?
    – Moha
    Apr 21, 2013 at 11:41

2 Answers 2

2

Although an old issue, the way to do this in D7 commerce is with

hook_commerce_entity_access

/**
 * Implements hook_commerce_entity_access
 */
function MODULE_commerce_entity_access($op, $entity, $account, $entity_type) {
  if ($entity_type == 'commerce_order') {
    // Prevent edit and delete of 'processed' status orders
    if ($entity->status == 'processed' && ($op == 'edit' || $op == 'delete')) {
      return FALSE;
    }
  }
}
1

You can user views_php module and can programmatically render edit and delete link after checking the required condidtions. So the following steps may help you

  1. Install views_php module

  2. now in your view add edit and delete and nid field but exclude them from display

  3. now add global php field in views and load the node using the nid(you can check using dpm($data); if you have devel installed) now get the node field value and check the condition and display the edit link which you can directly get as token as you have already added that field to views.

  4. follow the 3 rd step and this time render delete link. hope this helps you

1
  • I would not recommend adding PHP via the views UI, it is bad practice because the PHP is not version controlled and it is hard to debug problems later. Plus having PHP available via the UI adds security risk in that if someone gets access to edit the view they can run whatever PHP they like. - If the user is entering PHP then in theory they should also have the skills to create a custom module.
    – rooby
    Apr 21, 2013 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.