Panels integration ("content type")

mooffie - November 11, 2008 - 15:27
Project:Flag
Version:6.x-2.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed
Description

"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.)

AttachmentSize
flag_panels.diff4.29 KB

#1

mooffie - November 11, 2008 - 15:34

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

AttachmentSize
panels_add_content_box_shows_flag_links.png 47.87 KB

#2

mooffie - November 11, 2008 - 15:46

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

#3

mooffie - November 11, 2008 - 15:59
Title:Panels support ("content type")» Panels integration ("content type")

#4

mooffie - November 12, 2008 - 12:50
Status:active» needs review

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'.

AttachmentSize
flag_panels2.diff 926 bytes
link.inc 4.04 KB

#5

typehost - November 17, 2008 - 03:16

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.

AttachmentSize
panels.png 15.39 KB

#6

mooffie - November 17, 2008 - 14:58

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

#7

typehost - November 18, 2008 - 15:03

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.

#8

mooffie - November 18, 2008 - 15:46

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.

#9

typehost - November 19, 2008 - 02:47

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

#10

Flying Drupalist - November 20, 2008 - 13:44

Hi, D6 please! :)

#11

mooffie - November 20, 2008 - 15:35

"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.

#12

typehost - November 20, 2008 - 16:05

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.

#13

typehost - November 20, 2008 - 16:25

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!

#14

mooffie - November 20, 2008 - 16:55

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.

#15

typehost - November 20, 2008 - 17:35

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)

#16

typehost - November 20, 2008 - 17:41

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

#17

typehost - November 25, 2008 - 13:01

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?

#18

mooffie - November 25, 2008 - 15:07

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.

#19

mooffie - November 26, 2008 - 07:56

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

AttachmentSize
flag.panels.inc 3.88 KB
flag_panels3.diff 585 bytes

#20

typehost - November 26, 2008 - 12:08

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.

#21

thelocaltourist - January 16, 2009 - 20:04

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.

#22

EzS - February 15, 2009 - 16:47

This patch wasn't tested on D6.

How to do it in Drupal 6?

#23

mooffie - February 15, 2009 - 20:54

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.

#24

Buffer2k - March 15, 2009 - 01:02

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

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

#25

ctalley5 - May 12, 2009 - 02:42

Same here

#26

ctalley5 - May 18, 2009 - 18:14
Version:5.x-1.x-dev» 6.x-1.x-dev
Component:Code» Miscellaneous

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

#27

mrgoltra - June 1, 2009 - 19:11

subscribing. Trying to get this to work.

#28

chaosprinz - June 22, 2009 - 17:39

also subscribing for Drupal6 & Panels3

#29

quicksketch - June 23, 2009 - 01:18
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.

#30

ctalley5 - September 16, 2009 - 18:43

has anybody else had any luck with this yet

#31

mansspams - October 3, 2009 - 19:48

+1

#32

quicksketch - October 4, 2009 - 01:22
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.

#33

webanalya - October 21, 2009 - 13:29

also subscribing for D6 & Panels 3

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

- inserting

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

#34

nitram079 - November 3, 2009 - 17:44

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

 
 

Drupal is a registered trademark of Dries Buytaert.