0% found this document useful (0 votes)
343 views2 pages

Create Custom Pane Programmatically For Panels in Drupal 7

This document provides code examples for creating a custom content pane programmatically for Panels in Drupal 7. It includes adding a Panels dependency to the module info file, implementing a plugin directory hook, creating a plugin file with pane configuration and callbacks for administrative title, info, editing the content type form and rendering node content. The pane lets the user pick a node and display it on the panel.

Uploaded by

Coklat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
343 views2 pages

Create Custom Pane Programmatically For Panels in Drupal 7

This document provides code examples for creating a custom content pane programmatically for Panels in Drupal 7. It includes adding a Panels dependency to the module info file, implementing a plugin directory hook, creating a plugin file with pane configuration and callbacks for administrative title, info, editing the content type form and rendering node content. The pane lets the user pick a node and display it on the panel.

Uploaded by

Coklat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Create custom pane programmatically for Panels in Drupal 7

1 of 2

Create custom pane programmatically for Panels in Drupal 7


This shows code examples of what I had to do to create custom pane programmatically for Panels in Drupal 7. In this example I create new pane where you can pick your node and display it.

HOOK.info
I added panels dependency to my .info file.
1. dependencies[] = panels

HOOK.m odule plugin directory


Add ctools plugin directory hook. Also create a folder called "plugins" to your module file. In plugins directory create a folder called "content_types".
1. /**
2. * Implements hook_ctools_plugin_directory().
3. */
4. function HOOK_ctools_plugin_directory($module, $plugin) {
5.
if (($module == 'ctools' || $module == 'panels') && !empty($plugin)) {
6.
return 'plugins/' . $plugin;
7.
}
8. }

PANE.inc plugin file


Create a file that will be your plugin in plugins/content_types directory.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.

$plugin = array(
'title'
'single'
'description'
'category'
'all contexts'
);

=>
=>
=>
=>
=>

t('This is my custom pane.'),


FALSE,
t('My custom pane lets pick a node and display it.'),
array('My category'),
TRUE,

/**
* Title callback for admin page.
*/
function HOOK_PANE_admin_title($subtype, $conf, $context = NULL) {
return t('My custom pane');
}
/**
* Callback to provide administrative info (the preview in panels when building a panel).
*/
function HOOK_PANE_admin_info($subtype, $conf, $context = NULL) {
$block = new stdClass();
$block->title = t('Custom pane');
$config = array();
if ($conf['override_title'] == TRUE) {
$title_value = '<b>' . $conf['override_title_text'] . '</b>';
}
else {
$title_value = t('Not Set');
}
$config[] = t('Title') . ': ' . $title_value;
$block->content = theme_item_list(array( 'items' => $config, 'title' => NULL, 'type' => 'ul', 'attributes' => array() ));
return $block;
}
/**
* Edit callback for the content type.
*/
function HOOK_PANE_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
if ($form_state['op'] == 'add') {
$form['nid'] = array(
'#prefix' => '<div class="no-float">',
'#title' => t('Enter the title or NID of a node'),
'#description' => t('To use a NID from the URL, you may use %0, %1, ..., %N to get URL arguments. Or use @0, @1, @2, ..., @N to use arguments passed into the panel.'),
'#type' => 'textfield',
'#maxlength' => 512,
'#autocomplete_path' => 'ctools/autocomplete/node',
'#weight' => -10,
'#suffix' => '</div>',
);
}
else {
$form['nid'] = array(
'#type' => 'value',
'#value' => $conf['nid'],
);
}
return $form;
}
/**
* Submit callback for settings form.
*/
function HOOK_PANE_content_type_edit_form_submit($form, &$form_state) {
foreach (element_children($form) as $key) {
if (isset($form_state['values'][$key])) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
}
/**
* Run-time rendering of the body of the block (content type).
*/
function HOOK_PANE_content_type_render($subtype, $conf, $panel_args) {
$block = new stdClass();
if (isset($conf['nid'])) {
$block = new stdClass();
if ( $conf['override_title'] == TRUE ) {
$block->title = $conf['override_title_text'];
}
else {
$block->title = NULL;
}

http://browse-tutorials.com/tutorial/create-custom-pane-programmatical...

9/21/2014 5:43 AM

Create custom pane programmatically for Panels in Drupal 7

2 of 2

88.
89.
$nid_match = array();
90.
preg_match('/\[id: (\d*?)\]$/', $conf['nid'], $nid_match);
91.
$node = node_load($nid_match[1]);
92.
$block->content = node_view($node, 'teaser');
93.
94.
return $block;
95.
}
96.
return NULL;
97. }

http://browse-tutorials.com/tutorial/create-custom-pane-programmatical...

9/21/2014 5:43 AM

You might also like