Beruflich Dokumente
Kultur Dokumente
Step 1: Create a new custom m odule w ith this in the .m odule file:
/**
* Implements hook_ctools_plugin_directory().
*/
function examplemodule_ctools_plugin_directory($owner, $plugin_type) {
5.
if ($owner == 'ctools' && $plugin_type == 'content_types') {
return 'plugins/' . $plugin_type;
}
}
Where the name of my custom module is 'examplemodule'.
This lets ctools know that any file in the folder 'plugins/content_types/' should be parsed for content type plugins.
This also keeps your code really nice.
1 of 6
10.
);
This piece of code lets ctools know what functions to call, what argument defaults there are and so fourth. It should
be largely self explanatory. It also means that your pane will show up in panels now, as we can see from this
picture:
2 of 6
return $form;
25. }
In order to save the configuration back to the $conf storage for the pane, you will also need a submit handler
/**
* The submit form stores the data in $conf.
*/
function examplemodule_twitter_timeline_edit_form_submit($form, &$form_state) {
5.
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
if (isset($form_state['values'][$key])) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
10. }
There you have it, now you can configure the pane username, and the amount of tweets to show, all of which have
sane defaults and helpful descriptions for your content authors. This is what this step looks like:
3 of 6
10.
15.
20.
25.
30.
35.
4 of 6
40.
features: {
avatars: false,
hashtags: true,
scrollbar: false,
loop: true,
live: true,
behavior: "default"
}
});
45.
t.render().setUser("' . check_plain($conf['username']) . '").start();
</script>';
return $block;
50. }
Here is a sample panel page, with the twitter timelien pane on the right hand side
(http://www.pixelite.co.nz/sites/default/files/ctools-content-type-page-1.png)
And as you can imagine, it is relatively easy to add more panes onto the panel, here is another on the same page
5 of 6
(http://www.pixelite.co.nz/sites/default/files/ctools-content-type-page-2.png)
Final thoughts
In this tutorial you have seen how easy it is to make a fully custom ctools content type plugin, from scratch. And
hopefully begin to see how this is more powerful then traditional blocks.
What are your experiences with ctools content types, and helpful advice for others? Did this tutorial help you at all?
Let me know in the comments.
Source
Ctools (http://drupal.org/project/ctools)
6 of 6