t("Node: is flagged"), 'description' => t('Control access by whether or not a node is flagged.'), 'callback' => 'flag_is_flagged_ctools_access_check', 'default' => array('flag_name' => ''), 'settings form' => 'flag_is_flagged_ctools_access_settings', 'summary' => 'flag_flagged_ctools_access_summary', 'required context' => new ctools_context_required(t('Node'), 'node'), ); /** * Settings form */ function flag_is_flagged_ctools_access_settings($form, &$form_state, $conf) { $options = array(); foreach (flag_get_flags('node') as $flag) { $options[$flag->name] = check_plain($flag->title); } $form['settings']['flag_name'] = array( '#title' => t('Flag name'), '#type' => 'radios', '#options' => $options, '#description' => t('Include only flagged content.'), '#default_value' => $conf['flag_name'], ); return $form; } /** * Check for access. */ function flag_is_flagged_ctools_access_check($conf, $context) { // As far as I know there should always be a context at this point, but this // is safe. if (empty($context) || empty($context->data) || empty($context->data->nid)) { return FALSE; } if(!empty($conf['flag_name'])) { $flag = flag_get_flag($conf['flag_name']); if($flag) { return $flag->is_flagged($context->data->nid); } } return TRUE; } /** * Provide a summary description based upon the specified context */ function flag_is_flagged_ctools_access_summary($conf, $context) { if (!isset($conf['flag_name'])) { $conf['flag_name'] = ''; } $flags = flag_get_flags('node'); $flag = $conf['flag_name']; if (!empty($flag) && !empty($flags[$flag])) { return t('@identifier is flagged with "@flag"', array('@flag' => check_plain($flags[$flag]->title), '@identifier' => $context->identifier)); } else { return t('Missing/ deleted flag "@flag"', array('@flag' => $flag)); } }