Creating a content type with CTools for Panels 3

Comments

15 comments posted
April 22: I've incorporated

April 22: I've incorporated these comments except for the very last one since I haven't had a chance to try that out, yet.

Earl made some comments on IRC but my son is up from his nap so I can't work them into the article just yet. Pasting them here (with permission) until I have a chance to update the article.

[14:31] < merlinofchaos > Michelle: Hm. Step 1: You need a module. =)
[14:32] < merlinofchaos > Michelle: Ok. For the 'icon' it assumes it will be in the same directory as the plugin. If it is not you'll have to provide the full path to the icon. If you have no icon CTools provides a default, bland icon for you.
[14:34] < merlinofchaos > $block->module = 'author_pane'; is no longer necessary -- it's a relic from when we just used theme('block') to display panes. You can eliminate it.
[14:36] < merlinofchaos > I would also group the _submit with the form, since they are related. Having the _admin_title between the form and the _submit is minorly confusing. One last thing you missed is that there's a new _admin_info so you can specify what appears in the box on the drag & drop page. For example, the view type displays some of its config. Blocks just show you the block.

Thanks for the corrections, Earl!

Michelle

Posted by Michelle on Tue, 04/21/2009 - 14:42
Michelle, thanks so much for

Michelle, thanks so much for bringing this to us live!

CTools is definitely part of the Drupal Quiet Revolution, and amidst all the growing pains and work and daily obligations we all have, it is something that up till now has resided on my "got to get around to seeing that" list.

Despite your own obligations, I really thank you for making this effort and for socializing it, making it available to all of us. A real ray of sunshine!

Thanks!

Victor Kane
http://awebfactory.com.ar
http://projectflowandtracker.com

Posted by victorkane (not verified) on Wed, 04/22/2009 - 06:25
@victorkane: Glad you like

@victorkane: Glad you like it. Content types are one of the most useful (to me) parts of panels. And they really aren't hard to make once you grasp it. It took me a while (and a lot of help from Earl) to get past the hump and get everything named correctly so I wanted to help everyone else along by writing it up while it was still fresh in my mind.

Michelle

Posted by Michelle on Wed, 04/22/2009 - 22:28
Added to DrupalSightings.com
Posted by Jim (not verified) on Thu, 04/23/2009 - 09:26
Thanks for this article, it

Thanks for this article, it really helped a lot!

In order to get this example working in panels-6.x-3.0-alpha4, I had to add the key 'title callback' to the array returned by author_pane_author_pane_ctools_content_types():

function author_pane_author_pane_ctools_content_types() {
return array(
'single' => TRUE,
'title' => t('Author Pane'),
// NEW *REQUIRED* CALLBACK - otherwise you get "Deleted/missing content type" errors
'title callback'=>'author_pane_author_pane_title_callback',
'icon' => 'icon_user.png',
'description' => t('Author related variables gathered from helper modules.'),
'required context' => new ctools_context_required(t('User'), 'user'),
'category' => t('Advanced Profile Kit'),
'defaults' => array('image_path' => '', 'template_file' => 'author-pane'),
);
}

// callback for the title ...
function author_pane_author_pane_title_callback($subtype, $conf, $context, $incoming_content) {
}

Best, Fredrik!

Posted by Fredrik (not verified) on Thu, 04/23/2009 - 10:18
@Fredrik: This article is not

@Fredrik: This article is not meant for alpha 4. There have been a lot of changes since then. That's why I have the bold message at the top. ;)

Michelle

Posted by Michelle on Thu, 04/23/2009 - 10:50
ouch, indeed! oops, sorry, my

ouch, indeed! oops, sorry, my mistake :)

Posted by Fredrik (not verified) on Thu, 04/23/2009 - 11:09
Thanks a lot for this it was

Thanks a lot for this it was very helpfull :)

Do you have the same kind of tutorial for migrating panels2 context relationship to the new ctools-dev API ?

Because I have patched the content profile module for use with panels 3 (but in alpha), and i supposed that for the upcoming beta release (and the current dev snapshot) thing must have changed.

Here is my patch for using content profile with panels 3 ALPHA

? .svn
? content_profile_panels3.patch
? modules/.svn
? tests/.svn
? views/.svn
Index: sites/all/modules/content_profile/content_profile.panels.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/content_profile/Attic/content_profile.panels.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 sites/all/modules/content_profile/content_profile.panels.inc
--- sites/all/modules/content_profile/content_profile.panels.inc 4 Jan 2009 12:02:19 -0000 1.1.2.1
+++ sites/all/modules/content_profile/content_profile.panels.inc 16 Apr 2009 13:42:30 -0000
@@ -9,15 +9,15 @@
/**
* Plugin to provide an relationship handler for node from user
*/
-function content_profile_panels_relationships() {
+function content_profile_ctools_relationships() {
$args['node_from_user'] = array(
'title' => t("Profile Node from user"),
'keyword' => 'content_profile',
'description' => t('Adds a Content Profile from user context'),
- 'required context' => new panels_required_context(t('User'), 'user'),
+ 'required context' => new ctools_context_required(t('User'), 'user'),
'context' => 'content_profile_panels_context',
- 'settings form' => 'content_profile_panels_settings_form',
- 'settings form validate' => 'content_profile_panels_settings_form_validate',
+ 'settings form' => 'content_profile_ctools_settings_form',
+ 'settings form validate' => 'content_profile_ctools_settings_form_validate',
);
return $args;
}
@@ -25,10 +25,12 @@ function content_profile_panels_relation
/**
* Return a new context based on an existing context
*/
-function content_profile_panels_context($context = NULL, $conf) {
+function content_profile_ctools_context($context = NULL, $conf) {
+
+
// If unset it wants a generic, unfilled context, which is just NULL
if (empty($context->data)) {
- return panels_context_create_empty('node', NULL);
+ return ctools_context_create_empty('node', NULL);
}

if (isset($context->data->uid)) {
@@ -37,17 +39,17 @@ function content_profile_panels_context(
$content_profile_node = content_profile_load($conf['type'], $uid);

// Send it to panels
- return panels_context_create('node', $content_profile_node);
+ return ctools_context_create('node', $content_profile_node);
}
else {
- return panels_context_create_empty('node', NULL);
+ return ctools_context_create_empty('node', NULL);
}
}

/**
* Settings form for the relationship
*/
-function content_profile_panels_settings_form($conf) {
+function content_profile_ctools_settings_form($conf) {
$options = content_profile_get_types('names');
$form['type'] = array(
'#type' => 'select',

Posted by muldos (not verified) on Thu, 04/30/2009 - 04:49
No, this is all I've written.

No, this is all I've written. You should be able to look at the instructions / example here and compare it against what you have now to see the differences.

Michelle

Posted by Michelle on Thu, 04/30/2009 - 08:48
Thanks Michelle! This article

Thanks Michelle! This article was very useful. I had to created a content type to be able to put the breadcrumb trail in a panel pane.

Posted by Nathan (not verified) on Thu, 06/04/2009 - 16:56
Hi Michelle and very thanks

Hi Michelle and very thanks for this article.
I've a problem with context..in UI selector for context on my panel page I didn't get 'user' (only 'node', 'node add form', 'node edit form', taxonomy term' and 'taxonomy vocabulary').
I have to remove this line:

'required context' => new ctools_context_required(t('User'), 'user'),

for content type to appear.
I'm using version 6.x-3.0-beta2, so what I'm missing?

Thanks!
Luca

Posted by lussoluca (not verified) on Mon, 06/08/2009 - 04:29
@lussoluca: This article

@lussoluca: This article walks through an example that uses the user context. If you are using the node context then, yes, you'd need to change that to node.

Michelle

Posted by Michelle on Mon, 06/08/2009 - 09:34
Greatly written indeed… I

Greatly written indeed… I really enjoyed your article and found it to be very informative, keep up the good work, I’ll be coming back to read any of your future articles..
Thank you

rapida

Posted by Ada Wong (not verified) on Wed, 07/01/2009 - 09:16
Really helpful. I had a need

Really helpful. I had a need to do this and it worked perfectly. I had a question. in the plugins directory can you have multiple inc files? and then name the hooks differently?

Brian.

Posted by Brian (not verified) on Fri, 07/03/2009 - 14:00
I'm sorry but I haven't

I'm sorry but I haven't really had my head in Panels since I wrote this so it's all rather fuzzy and I don't remember. I guess try it and see. :)

Michelle

Posted by Michelle on Fri, 07/03/2009 - 21:42