Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
To find out if a url is flagged in code you do something like this... (it's using the methods provided by the flag object)
// Set $flag_name to whatever page flag you want to check
// Create a flag object
$flag = flag_get_flag($flag_name);
//Check if user has access to flag
if ($flag->user_access()) {
$url = (isset($_GET['q'])) ? $_GET['q'] : variable_get('site_frontpage', 'node');
$content_id = $flag->get_content_id($url);
if ($flag->is_flagged($content_id)) {
// Do something if the page is flagged
}
}
Depending on what you are doing you may or may not need the user access check.
Flagging without confirming
* Page gets flagged: one entry in table flag_page_data (makes content_ID for url), one in flag_content (which ties fcid - flag type - content ID - the user).
* Page gets unflagged: Entry is removed from flag_content but not from flag_page_data.
Flagging with confirming
* Page gets flagged -> two entries into table flag_page_data and one in flag_content.
* Page gets unflagged -> an additional third entry is made in flag_page_data, and the entry in flag_content is removed.
The screenshot for flag_page_data is attached; MMS was bookmarked without confirmation, Playground was bookmarked and unbookmarked with confirmation. These additional two entries don't make much sense to me, admittedly. An explanation would be welcome :)
If you use the version that is compatible with Flag 2.x the extra entries will not be put into the flag_page_data table. It has a way of lazily loading this table.
In the first version of flag page every page of the site will end up in flag_page_data whether it is flagged on not. Pages which are flagged end up in the flag_content table.
Also if you have further questions can you open a new issue as this issue has already been solved and closed. Thanks!
Comments
Comment #1
alexpottTo find out if a url is flagged in code you do something like this... (it's using the methods provided by the flag object)
Depending on what you are doing you may or may not need the user access check.
Comment #2
Igal commentedalexpott, thanks for the reply. It is works.
I noticed that if I unflag the page, the entry of unflagged page will not be deleted from flag_page_data_url table. Is this correct behavior?
Comment #4
itsnotme commentedIt looks like this to me:
Flagging without confirming
* Page gets flagged: one entry in table flag_page_data (makes content_ID for url), one in flag_content (which ties fcid - flag type - content ID - the user).
* Page gets unflagged: Entry is removed from flag_content but not from flag_page_data.
Flagging with confirming
* Page gets flagged -> two entries into table flag_page_data and one in flag_content.
* Page gets unflagged -> an additional third entry is made in flag_page_data, and the entry in flag_content is removed.
The screenshot for flag_page_data is attached; MMS was bookmarked without confirmation, Playground was bookmarked and unbookmarked with confirmation. These additional two entries don't make much sense to me, admittedly. An explanation would be welcome :)
Comment #5
alexpottHi itsnotme,
If you use the version that is compatible with Flag 2.x the extra entries will not be put into the flag_page_data table. It has a way of lazily loading this table.
In the first version of flag page every page of the site will end up in flag_page_data whether it is flagged on not. Pages which are flagged end up in the flag_content table.
Also if you have further questions can you open a new issue as this issue has already been solved and closed. Thanks!