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:
<?php
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.