| Commit | Line | Data |
|---|---|---|
| aee333f1 EM |
1 | The API for expanding the panels module comes in two pieces. First there is the \r |
| 2 | layout API, which adds to the list of layouts you need. Second is the content\r | |
| 3 | types API, which lets modules supply content to the panels. Natively, panels\r | |
| 4 | module supports the content types of 'block', which just renders the output\r | |
| 5 | of a block, 'node' which simply renders a node_view, 'custom' which allows the\r | |
| 6 | user to enter custom content with filtering, and finally 'views' because I\r | |
| 7 | wrote them both.\r | |
| 8 | \r | |
| 9 | Where to put your code:\r | |
| 10 | =======================\r | |
| 11 | \r | |
| 12 | With both types, there are two ways to implement a new type. First, you can\r | |
| 13 | implement the hook in your module and provide the necessary data. Or you\r | |
| 14 | can create a .inc file in the right format, and drop it into the proper\r | |
| 15 | directory in the panels module. Both are very similar, and only requires\r | |
| 16 | a minor naming adjustment.\r | |
| 17 | \r | |
| 18 | When using the .inc file, in place of 'hook' in the various hooks, use\r | |
| 19 | panels_FILENAME. \r | |
| 20 | \r | |
| 21 | Creating a new Layout Type:\r | |
| 22 | ===========================\r | |
| 23 | \r | |
| 24 | A layout consists of 4 things:\r | |
| 25 | \r | |
| 26 | 1) 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 | |
| 29 | 2) A bit of CSS to describe how the layout should be, well, laid out.\r | |
| 30 | 3) An icon that is 50x75 which gives the user a visual indication of\r | |
| 31 | what the layout looks like.\r | |
| 32 | 4) An implementation of hook_panels_layouts() to tell panels the necessary \r | |
| 33 | information.\r | |
| 34 | \r | |
| 35 | hook_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 | |
| 54 | Creating a new Content Type:\r | |
| 55 | ============================\r | |
| 56 | \r | |
| 57 | Content types require 1 hook and two callbacks. The hook defines what content \r | |
| 58 | types are available, the first callback displays the content in a dashboard, \r | |
| 59 | and the other callback does all of the administrative functions.\r | |
| 60 | \r | |
| 61 | hook_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 | |
| 65 | The callback function receives one argument: The $configuration array, as\r | |
| 66 | defined by the administrative callback.\r | |
| 67 | \r | |
| 68 | The 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 | |
| 76 | Administrative 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 |