"Content type", in Panels' sense, is "something you can put in a panel". Users are asking to put a flag link in a panel. This patch makes this possible.

Ideally, all this code should be placed in a separate '.inc' file. I hope to do that soon. (Panels' tech docs don't explain how to do this, not in a concise manner, so I haven't done this yet.)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mooffie’s picture

This screenshot shows how Panels' "Add content" box looks after applying the patch. You can see three flag-links there (one for each flag).

Those of you having x-ray vision can also see two user flags (they're hiding behind the "Screen S" window. Yeah, this screenshort is damaged, but I noticed that too late and it's a pain for me to make another, on my old computer.)

mooffie’s picture

NOTE TO DRUPAL 5 USERS:

If you're using Bio, or Usernode, you want to load this node. Panels has the concept of "Relationships". The "Relationship" section is on the "Context" tab. You'll be able to load the user's usernode there (I don't know about Bio). Once you add this node to the game, you'll have "Node context" in your "Add content" box (as in the screenshot).

mooffie’s picture

Title: Panels support ("content type") » Panels integration ("content type")
mooffie’s picture

Status: Active » Needs review
FileSize
926 bytes
4.04 KB
926 bytes

Here is a revised patch, where the code is moved to an '.inc' file. Because of the way Panels loads things, the Panels support shouldn't be placed directly in the 'includes' folder but in a folder of its own.

1. Apply the patch.
2. Put 'link.inc' in 'includes/panels'.

typehost’s picture

FileSize
15.39 KB

I am working on a site using Bio & Advanced Profile. I patched the Flag module, created & uploaded the links.inc file to includes/panels.

Created a bookmark only for Uprofile type, added "Node ID" as an argument & "User uprofile" as a relationship in the advanced profile panels page (see: screenshot).

(Note: by default, the advanced profile panel only had "User ID" as an argument and "Node from user" as relationship.)

No Flag blocks showing in the content section pop-ups.

Any suggestions on what needs to be done to configure this would be appreciated.

mooffie’s picture

Are you using D5? This patch wasn't tested on D6.

Could you please add the following line to the start of function flag_link_panels_content_types() (in link.inc) ?

drupal_set_message('Hello! I was called!');

(The purpose here is to verify that Panels loads and calls our code. You should see that 'Hello! ...' when configuring the panel.)

typehost’s picture

I have added:

function flag_link_panels_content_types() {
  drupal_set_message('Hello! I was called!');
  $items['flag_link'] = array(

to the link.inc file, and do not see "hello" when configuring the panel.

What I really need to do is be able to print the flag link in a specific part of a Panels block - which has a self-existing (APK) template.

Note: it is 5.x we are working with.

mooffie’s picture

I [...] do not see "hello" when configuring the panel.

Good. Problems where nothing happens are usually easier to solve.

Note that this "hello" you're supposed to see in Drupal's message area right after you click the "Content" tab. Perhaps you looked for it somewhere else.

The next step is to add the following...

drupal_set_message('This link.inc file was loaded!');

...to the "global" level of the link.inc file. In other words, somewhere outside of any function.

You should see this new message when you click the "Content" tab.

Make sure your server has permission to read this file. For example, if you created that link.inc file with only "600" permission, and the server isn't running as "you", then PHP won't be able to load this file.

typehost’s picture

I added

 */
drupal_set_message('This link.inc file was loaded!');

function flag_link_panels_content_types() {
  drupal_set_message('Hello! I was called!');
  $items['flag_link'] = array(

to the link.inc file - checked the permissions, it was set to 644
Changed the permissions to 755 (folder is also 755)
"This link.inc file was loaded!" message did not appear in the message section

Flying Drupalist’s picture

Hi, D6 please! :)

mooffie’s picture

"This link.inc file was loaded!" message did not appear

Great.

Now, open 'flag.module' in an editor. Locate the function flag_panels_include_directory(). Add the following line at the beginning of its body:

drupal_set_message("flag_panels_include_directory($plugin_type) was called!");

Let me know what messages, if any, you now see.

typehost’s picture

I added

function flag_panels_include_directory($plugin_type) {
  drupal_set_message("flag_panels_include_directory($plugin_type) was called!");
  if ($plugin_type == 'content_types') {

And I see the message as listed when first navigating to the panels page (list) - by the time I get to the settings page it is displayed 5 times in the message box.

typehost’s picture

To be more specific, on the content page:


    * flag_panels_include_directory(arguments) was called!
    * flag_panels_include_directory(contexts) was called!
    * flag_panels_include_directory(arguments) was called!
    * flag_panels_include_directory(contexts) was called!
    * flag_panels_include_directory(content_types) was called!
    * flag_panels_include_directory(layouts) was called!
    * flag_panels_include_directory(cache) was called!

mooffie’s picture

typehost, I want to make sure the server user can read the 'link.inc' file:

Create a new node, having the "PHP" input format.

Paste the following into its body:

<?php
$file = drupal_get_path('module', 'flag') . '/includes/panels/link.inc';
if (file_exists($file)) {
  print "File exists";
  if (is_readable($file)) { print "...and is readable"; }
  include $file;
}
else {
  print "File $file doesn't exist";
}
?>

When you preview, or view, this node, you'll see "File exists...and is readable", and in the message area you'll see "This link.inc file was included!" (provided you didn't remove that message form that file). Please confirm.

typehost’s picture

I received:

File sites/all/modules/flag/includes/panels/link.inc doesn't exist

which made it clear the mistake was I uploaded the file to /includes/panels (drupal core) and not to the flag module directory

changed that and received:

File exists...and is readable

Flag bookmarks now showing in the add content section of panels (thanks)

only thing - getting a "missing content type - Deleted/missing content type flag_link"

I have this bookmark only set to uprofile type, same result though when biography & user node are enabled
+ "Node from User" / "Node ID" / "User uprofile 2" are my three choices for the block configuration

the settings in context are the same as the screenshot above (panels.png)

typehost’s picture

Result I end up with is: Flag "" is not defined.

typehost’s picture

Bumping this again as I need to solve the issue - 1) is what is the reason for the Flag is not defined result, and 2) is there still not anyway to simply print the flag link in the template of the advanced profile page?

mooffie’s picture

what is the reason for the Flag is not defined result

Bug(s). In Panels, it seems. The good news is that I can reproduce the problem on my system, so I'll be able to debug it. I'll report back soon.

mooffie’s picture

FileSize
585 bytes
3.88 KB

Here's the updated Panels support.

1. Undo all the changes you made to the module.
2. Apply the patch.
3. Put 'flag.panels.inc' (make sure to fix the attachment's name) in the 'includes' sub-folder of the Flag module.

(You may have to re-add the links to the Panel. I don't know if the old links will work because Panels caches things.)

typehost’s picture

Nice - it is working perfectly now. I really appreciate your attention to these issues and assistance in working out the bugs. The functionality is important to our sites - many thanks.

thelocaltourist’s picture

How do I do this for D6?

Created flag.panels.inc
Added patch to flag.module

Uploaded

Flags appeared on Add Content To... in Panels2. When I inserted received the error: Error: Flag "f" is not defined.

Stan.Ezersky’s picture

This patch wasn't tested on D6.

How to do it in Drupal 6?

mooffie’s picture

This patch wasn't tested on D6.

How to do it in Drupal 6?

I don't know, I don't have access to Drupal.

Basically, Panels 2.x for D6 was supposed to be a straight port of Panels 2.x for D5. If the patch doesn't work in D6, as comment #21 suggests, it might mean they have changed the API slightly.

Witch’s picture

oh no :\ what can drupal 6 users do now? i need this feature.

hope that somebody can do this. i appreciate this very much!

ctalley5’s picture

Same here

ctalley5’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Component: Code » Miscellaneous

subscribe.... D6 & Panels 3???

mrgoltra’s picture

subscribing. Trying to get this to work.

chaosprinz’s picture

also subscribing for Drupal6 & Panels3

quicksketch’s picture

Status: Needs review » Needs work

Needs work for the D6 version of panels (3.x), at this point I don't think it's worth maintaining a Drupal 5 version of this feature.

ctalley5’s picture

has anybody else had any luck with this yet

mansspams’s picture

+1

quicksketch’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs work » Postponed

Moving to 2.x where all new features are being added. I don't use Panels module so I'm very unlikely to develop such a feature. Unless a community developer puts this together, this is unlikely to happen.

webanalya’s picture

also subscribing for D6 & Panels 3

--------------
I circumvented the problem by amending node.tpl.php of my theme:

- inserting print flag_create_link('bookmarks', $node->nid); in the link section ;
- create a pane with node > node links

nitram079’s picture

There is actually a quite easy solution for this, however, not as easy as directly from panel. Here is what you do:
- create a view that displays a flag link for the corresponding node

In my case, I have a node type for a video page on my site and have three flags: like, bookmark, report

Below is the views export for a) only one flag (in my case the like flag) and b) for all three of my flags

$view = new view;
$view->name = 'test_flags_link';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'flag_content_rel' => array(
    'label' => 'flag',
    'required' => 0,
    'flag' => 'like',
    'user_scope' => 'current',
    'id' => 'flag_content_rel',
    'table' => 'node',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'ops' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_type' => 'toggle',
    'exclude' => 0,
    'id' => 'ops',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel',
  ),
));
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'node',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'panel' => 0,
      'profile' => 0,
      'story' => 0,
      'uprofile' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '6' => 0,
      '2' => 0,
      '3' => 0,
      '4' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

$view = new view;
$view->name = 'test_flags_link';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'flag_content_rel' => array(
    'label' => 'like',
    'required' => 0,
    'flag' => 'like',
    'user_scope' => 'current',
    'id' => 'flag_content_rel',
    'table' => 'node',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
  ),
  'flag_content_rel_1' => array(
    'label' => 'bookmark',
    'required' => 0,
    'flag' => 'bookmarks',
    'user_scope' => 'current',
    'id' => 'flag_content_rel_1',
    'table' => 'node',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
  ),
  'flag_content_rel_2' => array(
    'label' => 'report',
    'required' => 0,
    'flag' => 'report',
    'user_scope' => 'current',
    'id' => 'flag_content_rel_2',
    'table' => 'node',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'ops' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_type' => 'toggle',
    'exclude' => 0,
    'id' => 'ops',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel',
  ),
  'ops_1' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_type' => '',
    'exclude' => 0,
    'id' => 'ops_1',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel_1',
  ),
  'ops_2' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_type' => '',
    'exclude' => 0,
    'id' => 'ops_2',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel_2',
  ),
));
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'node',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'panel' => 0,
      'profile' => 0,
      'story' => 0,
      'uprofile' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '6' => 0,
      '2' => 0,
      '3' => 0,
      '4' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

BenK’s picture

Subscribing...

coolhandlukek2’s picture

Subscribing...

glitz’s picture

subscribing. need to attach a flag to a panel page.

mansspams’s picture

Title: Panels integration ("content type") » Panels integration

Panels integration must include:

- Ability to add flags to node/user pages
- Ability to check if content is flagged in access rules
- Ability to check flag status in selection rules, so page can use different variants depending on flag status
- Load flag and flagger as context and/or argument
- ... (more?)

glitz’s picture

got it, thanks

freelylw’s picture

when we will have a panels version of flag ? its a important function since panels is widely used in drupal.

quicksketch’s picture

when we will have a panels version of flag ?

When someone writes it. :P

I don't use Panels, and I'm not going to write integration for something I don't use. Considering I won't be able to maintain such code, it may end up in a separate project entirely.

mansspams’s picture

Assigned: Unassigned » mansspams
Status: Postponed » Active

ok, ill write it, im not much of a writer, but I hope it will turn out awesome... right now I am consulting with allmighty merlin over at #889088: flag ctools integration. go there, there is some code you can try out...

mansspams’s picture

content type plug-in is also available at #889088: flag ctools integration It will allow you to display flag links as well as display flag status in panels.

mansspams’s picture

Title: Panels integration » Flag Ctools integration
FileSize
6.23 KB

this is latest version, wrapped into a module. Drop this in flag folder or in modules, activate under Flags.

Has access and content types plugins, other soon. Questions, comments?

g76’s picture

This would be incredible, thank you so much for your work.

I can seem to get it to work, I was hoping you could help, it may be something I have done wrong. I am not a coder, but would be more than happy to be an active tester if you have need. I have dropped ctools_flag into the modules dir, but I am not seeing any change in panels.

Your module would be a complete solution to what I am looking for, so I can not thank you enough. I have been looking for a way to create panels "layout" variants and be able to select them or change them on the fly instead of creating/cloning variants for each instance. Since my navigation/site structure is taxonomy based and I am overriding the tax term view in panels, I thought it may be possible to use the flag terms module to flag a term in the site structure vocab as "Layout 1", "Layout 2", etc... and then apply the flag as a selection rule. This would negate the need to create cloned variants per tax term just to change the panel page a bit. Also, the layouts can be adjusted on the fly.

I hope this makes sense. If there is another way to accomplish this that you know, please let me know. I would love any input you would have to offer.

thanks again

mansspams’s picture

Currently only node flags are supported, Ill work on it a little more to add user and term support.

g76’s picture

thank you so much.

lpalgarvio’s picture

subscribing

lpalgarvio’s picture

good job :)

i can confirm that it is working well, when directly included in a Panel

-------------------------------------------------------------------------------------------------------
Flags also work well as before, with or without this module, when using as a Field in a View included in a Panel.
the View itself also works well, even with a nid argument (which is supplied by Panels when inside a panel).

so there is no conflict, even when using both methods at same time in a panel :P
-------------------------------------------------------------------------------------------------------

please commit to the module, in the main module or as a standalone module (included or not with Flags).
thanks

mooffie’s picture

LavaMeTender, it would be nice if you published this module on Drupal.Org, as an independent module.

lpalgarvio’s picture

Status: Active » Reviewed & tested by the community

works pretty well :)

commit it somewhere :P

lpalgarvio’s picture

other working solutions:
Fivestar panels integration - http://drupal.org/node/703614
Ubercart panels integration - http://drupal.org/node/658732

mansspams’s picture

Status: Reviewed & tested by the community » Active

This will be independent module as soon as it is ready.

Vote_Sizing_Steve’s picture

Subscribing

freelylw’s picture

Is user flags are supported now ? I am using the APK, waitting for the user flags, thanks

rbrownell’s picture

Any activity on this? What are our options?

rbrownell’s picture

#53 What is the module going to be called? Does it have a project page yet?

itserich’s picture

So to add flags for panels, the zip file in #44 is downloaded into all/modules OR all/modules/flag and extracted?

Then enabled?

Thank you!

EDIT I installed the zip in all/modules, extracted it, enabled it like a regular module. Went to a panel -> add content -> flag -> flag links.

Seems to work great. Hope it becomes a module, easier for people to find!

Thank you!

lpalgarvio’s picture

works just like a regular module

itserich’s picture

Yes thank you it is a big relief.

kevinwalsh’s picture

Tested, works great.

itserich’s picture

It should be made easier to find, if possible.

tim.plunkett’s picture

Status: Active » Needs review

What is left for this to be released?

mansspams’s picture

Status: Needs review » Active

Still under construction.

tim.plunkett’s picture

Is it going to be a sub-module or standalone? Either way, can it go into CVS?
Is it being developed on github or something?

If it was on d.o, then users could open up issues against it, or at least see what the timeline was.

freelylw’s picture

any progress for this module ? Thanks

bjsomers’s picture

+1

lpalgarvio’s picture

Needs caching support in Panels. and with AJAX.

at this point, for it to work, you should disable global caching for the panel in question, and instead enable local caching for each item you place as content in your panel, except for flag.

Exploratus’s picture

+1

marcxy’s picture

Node: Profile Node
User: User being viewed

Flag: Bookmarks

When I add to my "Content Profile/APK" panel, I see this when I click on a user:

* warning: array_keys() [function.array-keys]: The first argument should be an array in /home/marc/domains/mywebsite.com/public_html/sites/all/modules/flag/flag.inc on line 347.

* warning: array_intersect() [function.array-intersect]: Argument #2 is not an array in /home/marc/domains/mywebsite.com/public_html/sites/all/modules/flag/flag.inc on line 347.

* warning: array_keys() [function.array-keys]: The first argument should be an array in /home/marc/domains/mywebsite.com/public_html/sites/all/modules/flag/flag.inc on line 347.

* warning: array_intersect() [function.array-intersect]: Argument #2 is not an array in /home/marc/domains/mywebsite.com/public_html/sites/all/modules/flag/flag.inc on line 347.

* warning: array_keys() [function.array-keys]: The first argument should be an array in /home/marc/domains/mywebsite.com/public_html/sites/all/modules/flag/flag.inc on line 347.

* warning: array_intersect() [function.array-intersect]: Argument #2 is not an array in /home/marc/domains/mywebsite.com/public_html/sites/all/modules/flag/flag.inc on line 347.

marcxy’s picture

When I switch to

User: No Context

the errors are gone.

However, in both cases, I still do not see a link.

thanks!

karlitos’s picture

WOW!!! thank you soo much for this patch. Works great!!

Shadlington’s picture

Subscribing

lsolesen’s picture

+1

amitaibu’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Assigned: mansspams » Unassigned
Status: Active » Needs review
FileSize
3.08 KB

Here's a new take, for D7 (porting back to 6 should be fairly easy).

Patch adds a ctools plugin that allows you to select the flag, and pass user/ node/ comment context, and on render uses flag_create_link() if context really exists.

amitaibu’s picture

FileSize
3.22 KB

Here's the D6 version

amitaibu’s picture

Minor fix -- have the flag's name as the block delta instead of the flag ID. Attached D6 and D7.

amitaibu’s picture

FileSize
18.56 KB

Here's a screenshot.

jastraat’s picture

FileSize
1.99 KB

Expanding on the idea of ctools integration, I've written an access plugin for checking if a node is flagged. (This would require the flag_ctools_plugin_directory function from above, and this include file would go in plugins/access.)

amitaibu’s picture

@jastraat ,
1) Please open a different issue.
2) Please patch is correctly.
3) Flag is not node centric, the patch, similar to mine should allow user/ node/ comments (at least).

jastraat’s picture

My hesitation for opening a separate issue is that this depends on the flag_ctools_plugin_directory function as well. Should I assume that function does not exist in flag when I create a patch file?

perarnet’s picture

Patch in #77 applied against 7.x-dev and tests so far shows it is working well

rogical’s picture

+1
hope to see this fixed soon

fuzzybearuk’s picture

Category: feature » support

Would really appreciate some help here. I applied the ctools-plugin-flag-77-d7.patch but still cannot get the flag to work in Panels - I presume there should be an option in the panels content options?

Shadlington’s picture

Category: support » feature
dddave’s picture

Status: Needs review » Needs work

per #84 and I guess this patch need a reroll anyways.

andypost’s picture

  'required context' => new ctools_context_required(t('Node'), 'node'),

probably D7 could use Entity context and limit flags with entity type

  foreach (flag_get_flags('node') as $flag) {
    $options[$flag->name] = check_plain($flag->title);

Should they filtered by node-type

amitaibu’s picture

@andypost, the patch in #77 is the correct one.

andypost’s picture

I thonk #77 & #79 should be in one patch -access and content type plugins

Shadlington’s picture

Any progress on this?

#77 worked perfectly for me (though the patch isn't formatted correctly - needs the a/bluh b/bluh style)

andypost’s picture

Both #77 and #79 needs re-roll & re-factoring to able to be used with any entity that Flag module supports.

Probably#79 should be filed as another issue because it introduces

#77 Content-type plugin

+++ plugins/content_types/flag_link/flag_link.incundefined
@@ -0,0 +1,97 @@
+  'required context' => array(
+    new ctools_context_optional(t('User'), 'user'),
+    new ctools_context_optional(t('Node'), 'node'),
+    new ctools_context_optional(t('Comment'), 'comment'),

This should be converted to Entity:

+++ plugins/content_types/flag_link/flag_link.incundefined
@@ -0,0 +1,97 @@
+  // Check if we have the context for this flag type.
+  list($user_context, $node_context, $comment_context) = $context;
+  $current_context = ${$flag->content_type . '_context'};
+
+  if (empty($current_context->data)) {
+    return;
+  }

same

#79 Access plugin

  'required context' => new ctools_context_required(t('Node'), 'node'),

Any supported entity type!

  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);

This logic require some work

joachim’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
jherencia’s picture

Assigned: Unassigned » jherencia
FileSize
3.52 KB

Ok, here is #77 rerolled and adapted to entity as #91.

I'm currently working on the access plugin.

jherencia’s picture

Assigned: jherencia » Unassigned
Status: Needs work » Needs review
FileSize
6.55 KB
7.24 KB

And here is #77+#79 rerolled to 7.x-3.x and compatible with any entity.

andypost’s picture

@jherencia Awesome! I think this needs more reviews and manual testing. Overall looks great!

Minor things... I can't test them right now

+++ b/plugins/access/flag_is_flagged/flag_is_flagged.incundefined
@@ -0,0 +1,96 @@
+  // Get the ID of the entity.
+  list($id) = entity_extract_ids($flag->entity_type, $context->data);

now sure it works, suppose list($id,,) better

+++ b/plugins/content_types/flag_link/flag_link.incundefined
@@ -0,0 +1,116 @@
+  'content type' => 'flag_flag_link_content_type_info',

Interesting solution, should be tested

+++ b/plugins/content_types/flag_link/flag_link.incundefined
@@ -0,0 +1,116 @@
+  if (empty($context->data)) {
+    return;
+  }
+
+  // Get the ID of the entity.
+  list($id) = entity_extract_ids($flag->entity_type, $context->data);
+  $link = flag_create_link($flag->name, $id);

Suppose here need a check that entity type is flaggable

joachim’s picture

Status: Needs review » Needs work
avr’s picture

Status: Needs work » Needs review
FileSize
7.21 KB

I needed this functionality so I took a quick look at the patch in 94 and updated the few items mentioned by @andypost.

The flag_flag_link_content_type_info is working as expected for me - in panels with node and user contexts (and a combination of the two).

From what I can tell flag_create_link already provides all the necessary access checks through flag::access.

One other note, it would make more sense to me to use the $info['label'] for the category within Panels. When looking for the user link, I immediately when to the "User" category first - before checking "Entity".

I didn't check anything with the access plugin.

joachim’s picture

Status: Needs review » Needs work

Looks good.

Spotted this which looks like a 2.x API flag property:

+++ b/plugins/content_types/flag_link/flag_link.inc
@@ -0,0 +1,116 @@
+  list($id,,) = entity_extract_ids($flag->content_type, $context->data);

I don't have panels installed myself, so I'd appreciate it if users of panels could try this out and give feedback.

avr’s picture

Yep - completely missed the version number here. I had 2.x installed (at least you know it can be backported!).

I'll test again with 3.x-dev and update that property.

avr’s picture

Okay - tested with the 3.x-dev version and updated property.

I went ahead and created separate patches: 1 for the access plugin, 1 for the content type plugin, and one that combines both.

avr’s picture

Status: Needs work » Needs review

Updating status

Wayne22’s picture

Im pretty new to drupal, how do you apply the patch ?
Could you patch the file and Post it along with where to replace it in the directory?

joachim’s picture

Wayne22’s picture

Could you patch the file and Post it along with where to replace it in the directory?
I am not a great DRUPAL NINJA such as yourself. Thank you

mvc’s picture

Status: Needs review » Reviewed & tested by the community

@avr works perfectly for me, worth upgrading to 3.x for :) thanks!

@Wayne Leyden: with all due respect, using development branches of modules, let alone applying experimental patches, is an advanced drupal skill. if you don't know how to do it yourself and your technical level is not high enough to follow those instructions, you probably should wait until the change has been officially reviewed and applied.

joachim’s picture

Status: Reviewed & tested by the community » Needs work

Could I have a single patch please, rather than 3?

avr’s picture

The first patch in the group above is a single patch.

andypost’s picture

Status: Needs work » Reviewed & tested by the community

#100 flag-ctools_integration-332956-100.patch is right one

jherencia’s picture

Happy to see this RTBC, thank you @avr to continue my work :).

joachim’s picture

Status: Reviewed & tested by the community » Fixed

Committed, with a few tweaks:

- 'node' changed to 'entity'
- a few documentation changes

Thanks to everyone who's worked on this.

Issue #332956 by Amitaibu, mooffie, jherencia, avr, jastraat: Added Ctools plugins for content type and access.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Cromian’s picture

Hi everyone sorry to bother but was this added to 7.x-2.1? or 7.x-3.2 I am using 7.x-2.1 due to flag friends and wanted to know what patch I should use?

Cromian’s picture

Hi everyone sorry to bother but was this added to 7.x-2.1? or 7.x-3.2 I am using 7.x-2.1 due to flag friends and wanted to know what patch I should use?

Pasqualle’s picture

The ctools integration is in 7.x-3.2 (and 7.x-3.x-dev).
The 7.x-2.1 (and current 7.x-2.x-dev) release does not have ctools integration.