4

I have a global flag, spam, that has a textfield, reason, attached to it.

According to the Flag API documentation, I know I can check whether a user is flagged like this:

$spam && $spam->is_flagged($account->uid)

However, in this case, I want to retrieve the flagging, and then check the value of a field in that flagging. I didn't see any directions for doing so in the documentation, so I'm at a loss about how best to proceed.

  • What type of var is $spam? Hopefully it's flag_entity but maybe it's flag_flag? – Clive Nov 28 '15 at 18:18
3

According to the Flag API

flagging_load

Loads a flagging entity. Parameters

$flagging_id: The 'flagging_id' database serial column.

$reset: Whether to reset the DrupalDefaultEntityController cache. Return value

The entity object, or FALSE if it can't be found

Therefore something like this might work:

$flaggings = flag_get_user_flags('node', $node->nid);
if (isset($flaggings['spam'])) {
    $flagging = flagging_load($flaggings['spam']->flagging_id);
}

You will then find your field in:

$flagging->field_reason
| improve this answer | |

Your Answer

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

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