I have a workflow system for my nodes, one of the states is "Disable". also there are some flags on those nodes as well, I'd like to know if there's a way to revoke access of author to use flags when he changes the state of workflow to Disable.

Edit: There's a listing of nodes by the logged-in user which is the author, these nodes have different workflow states and different type of flags which each of those flags, does a certain action. In some cases author might wanna change workflow states to different ones, but when he changes the workflow to "Disable", he shouldn't have access to flags on that exact node that has "Disable" state on it.

Changing state to "Disable" revoke access to all flags on that node. In a rare situation, an admin might change the Workflow state back to something else, which obviously should grant access to the flags for the author, but author himself can't change the state back when he once "disabled" it using workflow.


Author's list:

Node1 : current workflow state: active, thus accessing to all flags.

Node2 : current workflow state: disable, thus no access to flags.

Note that Author can change workflow from Active to Disable, not vice versa.

Note2: Also I managed to get a rule to flag the node as disabled if the node workflow state is set to disabled, so we might be able to use flag only relation as well, for instance if disabled flag is flagged, deny access to all other flags of the node.

I'm looking for any solution, contrib module or a custom one, or just combination of modules maybe (Rules & flag), whatever that works!

I'm not sure if hook_flag_access() is relevant here or not.

thanks so much.

  • I updated the question my friend – user23288 Jul 27 '15 at 12:04
  • ok, that helps ... hang on for a possible solution to consider ... something related to your "whatever works" ... and no need for a custom module ... – Pierre.Vriens Jul 27 '15 at 12:27
  • remercie beaucoup ton frere – user23288 Jul 27 '15 at 12:30

If you need custom module, you can try this code

 * Check status of node
 * @param $nid
 * @param $fid
 * @return $result
 * if node have status disable return array()
 * if node have status active return NUll
function check_workflow_status($nid, $fid){
  $result = db_select('flagging', 'fg')
    ->fields('fg', array('entity_id'))
    ->condition('entity_id', $nid, '=')
    ->condition('fid', $fid, '=')
  return $result;

 * Implement hook_flag_access()
function YOURMODULE_flag_access($flag, $entity_id, $action, $account) {
  // Change flag id with your flag's ID
  // You can dpm($flag) to see flag id of status node.
  $result = check_workflow_status($entity_id, 1);
  if (!empty($result)) {
    // You need check special use have permission use flag status
    if (user_access('flag node_status'))
      return TRUE;
      // Deny access to all other flags of the node. 
      return FALSE;


You can get string in user_access() at here.

  • unfortunately since I'm not a developer, I couldn't make this work, can you please elaborate more? – user23288 Jul 28 '15 at 7:28
  • Can you write a simplate module? And do you get string in user_acess() function? – MrD Jul 28 '15 at 8:23
  • Well I'm a newbie in php, but I can understand the concept, I already created the module, but can't make that user_access() function working! – user23288 Jul 28 '15 at 11:00
  • 1
    It's so easy. You need copy my code in your file .module. And replace "YOURMODULE" with your name module. Final you need get your string to replace in my code. I think if you see link above, you can get it. And you need install module devel to see fid (drupal.org/project/devel). – MrD Jul 28 '15 at 11:35

hook_flag_access and hook_flag_multiple_access() do seem to be the way to go. You will need to write a small custom module for that, which you can read more from here.

An example implementation is below:


function MYMODULE_flag_access($flag, $entity_id, $action, $account) {
  if ($flag->name == 'NAME' && $flag->entity_type == 'node') {// Change flag name with your flag's machine name.
    $node = node_load($entity_id);
    if ($node && $node->uid == $account->uid) {
      return FALSE;

  return NULL;

function MYMODULE_flag_access_multiple($flag, $entity_ids, $account) {
  if ($flag->name == 'NAME' && $flag->entity_type == 'node') { // Change flag name with your flag's machine name.
    $nodes = node_load_multiple($entity_ids);
    foreach ($nodes as &$node) {
      $node = $node->uid == $account->uid ? FALSE : NULL;
    return $nodes;
  return array();

You will need to change "MYMODULE" with a module name of your choice, and use the same name and save it as MYMODULE.module. Accompany with the MYMODULE.info, drop in a folder and activate the module. Above is a sample code for you to start with the module. It checks if the Flag's entity type is node. If it's node, the relevant node(s) will be loaded, and the user ID will be matched against the provided account's user ID. If they match, it returns FALSE, indicating access should be denied. It does not explicitly return TRUE, to allow the basic Flag access checks and potential other modules to determine the access.

  • Thanks for the answer Ayesh, but what the above module does is only deny access to the said flag 'NAME'. but I can still use this approach, I used a rule that if I change workflow, a flag called 'disabled' will be flagged as well, so what we need to do here is to say if the 'disabled' flag is flagged, then deny access to all flags of the said node – user23288 Jul 27 '15 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy