t('Flag link'), 'single' => FALSE, 'content_types' => 'flag_panels_link_content_types', 'title callback' => 'flag_panels_link_title', 'add callback' => 'flag_panels_link_add', 'edit callback' => 'flag_panels_link_edit', 'render callback' => 'flag_panels_link_render', ); return $items; } /** * Callback. Returns all flag links available, each as a "content type". */ function flag_panels_link_content_types() { $items = array(); $flags = flag_get_flags(); foreach ($flags as $flag) { $info = array( 'title' => t('Flag link (@flag-title)', array('@flag-title' => $flag->get_title())), // For the time being, let's borrow Views' icon. 'icon' => 'icon_views_page.png', 'path' => panels_get_path('content_types/views'), ); switch ($flag->content_type) { case 'node': $info += array( 'description' => t('A link to flag, or unflag, a node.'), 'required context' => new panels_required_context(t('Node'), 'node'), 'category' => t('Node context'), ); break; case 'user': $info += array( 'description' => t('A link to flag, or unflag, a user.'), 'required context' => new panels_required_context(t('User'), 'user'), 'category' => t('User context'), ); break; case 'term': $info += array( 'description' => t('A link to flag, or unflag, a taxonomy term.'), 'required context' => new panels_required_context(t('Term'), 'term'), 'category' => t('Term context'), ); break; default: $info = array(); } if ($info) { $items['flag_link_' . $flag->name] = $info; } } return $items; } /** * Callback. Returns an administrative title for the link. */ function flag_panels_link_title($conf, $context) { $flag_name = $conf['flag_name']; $flag = flag_get_flag($flag_name); if ($flag) { return t('"@s" flag/unflag link', array('@s' => $flag->get_title())); } else { return t('Error: Flag "@s" is not defined.', array('@s' => $flag_name)); } } /** * Callback. Returns the form for a new link. */ function flag_panels_link_add($id, $parents, $conf = array()) { $conf['flag_name'] = substr($id, strlen('flag_link_')); return flag_panels_link_edit($id, $parents, $conf); } /** * Callback. Returns an edit form for a link. */ function flag_panels_link_edit($id, $parents, $conf) { $form['flag_name'] = array( '#type' => 'value', '#value' => $conf['flag_name'], ); $form['flag_reminder_message'] = array( '#type' => 'markup', '#value' => '

' . t("A reminder: the flag (or unflag) link won't show unless in the flag's settings page you have enabled this flag for this object. For example, if the flag is used to flag nodes, then if the object being displayed is a node of type 'story' but you've enabled the flag for nodes of type 'page' only, the link won't show.", array('@flag-settings-url' => url('admin/build/flags/edit/' . $conf['flag_name']))) . '

', ); return $form; } /** * Callback. Renders a flag link */ function flag_panels_link_render($conf, $panel_args, $context) { if (!empty($context) && empty($context->data)) { return; } $flag_name = $conf['flag_name']; $flag = flag_get_flag($flag_name); if ($flag) { $link->title = $flag->get_title(); $link->content = flag_create_link($flag_name, $flag->get_content_id($context->data)); } else { $link->title = t('Flag "@flag-name" is not defined.', array('@flag-name' => $flag_name)); $link->content = $link->title; } return $link; }