#118954 (by slantview) respect block visibility settings
[project/panels.git] / API.txt
CommitLineData
aee333f1
EM
1The API for expanding the panels module comes in two pieces. First there is the \r
2layout API, which adds to the list of layouts you need. Second is the content\r
3types API, which lets modules supply content to the panels. Natively, panels\r
4module supports the content types of 'block', which just renders the output\r
5of a block, 'node' which simply renders a node_view, 'custom' which allows the\r
6user to enter custom content with filtering, and finally 'views' because I\r
7wrote them both.\r
8\r
9Where to put your code:\r
10=======================\r
11\r
12With both types, there are two ways to implement a new type. First, you can\r
13implement the hook in your module and provide the necessary data. Or you\r
14can create a .inc file in the right format, and drop it into the proper\r
15directory in the panels module. Both are very similar, and only requires\r
16a minor naming adjustment.\r
17\r
18When using the .inc file, in place of 'hook' in the various hooks, use\r
19panels_FILENAME. \r
20\r
21Creating a new Layout Type:\r
22===========================\r
23\r
24A layout consists of 4 things:\r
25\r
261) A bit of HTML in a theme function. I use heredoc notation to make it\r
27 extra easy to convert these to .tpl.inc files in case they are to\r
28 be overridden in php template.\r
292) A bit of CSS to describe how the layout should be, well, laid out.\r
303) An icon that is 50x75 which gives the user a visual indication of\r
31 what the layout looks like.\r
324) An implementation of hook_panels_layouts() to tell panels the necessary \r
33 information.\r
34\r
35hook_panels_layouts returns an array with the following information:\r
36\r
37'module' => The module name providing this. This is necessary because it\r
38 uses drupal_get_path('module', $module) to get the proper\r
39 path for included CSS.\r
40'title' => The title of the layout presented to the user. Use t().\r
41'icon' => The filename of the icon to use when listing avialable layouts.\r
42'theme' => The theme function that contains the HTML, without the theme_ \r
43 part.\r
44'css' => The CSS file.\r
45'content areas' => an array in the form of 'name' => t('Title') of content\r
46 areas supported by the layout. For example, the simple\r
47 2 column layout uses array('left' => t('Left side'), \r
48 'right' => t('Right side')); -- the name is the internal\r
49 identifier. Your theme function will see it as \r
50 $content['name'] (so twocol gets $content['left'] and\r
51 $content['right']).\r
52\r
53\r
54Creating a new Content Type:\r
55============================\r
56\r
57Content types require 1 hook and two callbacks. The hook defines what content \r
58types are available, the first callback displays the content in a dashboard, \r
59and the other callback does all of the administrative functions.\r
60\r
61hook_panels_content_types returns an array with the following information:\r
62'callback' => The function to display the content.\r
63'admin' => The function to administer the content.\r
64\r
65The callback function receives one argument: The $configuration array, as\r
66defined by the administrative callback.\r
67\r
68The administrative callback recieves 3 arguments:\r
69\r
70$op -- the operation to perform. See below.\r
71&$arg1 -- The first argument should be a reference and its meaning varies \r
72 based on the op.\r
73$arg2 -- The second argument is optional, not a reference, and should \r
74 default to NULL.\r
75\r
76Administrative operations:\r
77\r
78'list': $arg1 is the configuration array.\r
79 This op is called when panels lists what content is in a content\r
80 area. It generally returns something similar to this:\r
81 return '<strong>Views</strong>: ' . $view->name . ' (' . $view->description . ')';\r
82\r
83'add button': arguments not used here.\r
84 This op is called to display the 'add content type' button; it can also\r
85 display additional information (such as the list of blocks or the\r
86 autocomplete to select a node).\r
87\r
88 The actual button should look something like this:\r
89 $form['submit'] = array(\r
90 '#type' => 'button',\r
91 '#value' => t('Add view'),\r
92 );\r
93\r
94 And it's a good idea to do this, but it's not required:\r
95\r
96 $form['#prefix'] = '<div class="container-inline">';\r
97 $form['#suffix'] = '</div>';\r
98\r
99'add': $arg1 == the $configuration array\r
100 This op is called to see if your add button has been clicked. It *must*\r
101 start off by checking to see if this is true:\r
102\r
103 if ($_POST['op'] != t('Add view')) {\r
104 return;\r
105 }\r
106\r
107 If it is true, it should process that information and return a $configuration\r
108 array populated from whatever other form items were presented in 'add button'\r
109 and whatever defaults make sense.\r
110\r
111'edit': $arg1 == the $configuration array\r
112 This op is called to provide an edit form for a content type. It *must*\r
113 ensure *all* information from the conf array is available, even if it\r
114 is just hidden; panels has no way to remember this data between form\r
115 clicks, so any data not put here will be lost. No buttons need to be\r
116 added to the form.\r
117\r
118'validate': $arg1 == $form_values, $arg2 == $form\r
119 Called to validate the 'edit' form above.\r
120\r
121'save': $arg1 == $form_values\r
122 Called to convert a $form_values back into a $configuration array. All\r
123 of the default types just send $form_values back as $configuration,\r
124 but if you need to do some kind of transformation, this is where it\r
125 happens.\r