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.

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

1 Answer 1

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

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.