6 * Page wizard that can create a variant on the node_view to take over a node
7 * for a particular type.
9 * This wizard does a lot that's cut and pasted from exports. We can get away
10 * with this because we know exports tend to remain relatively backward
11 * compatible, and because we know that our context IDs are locked in the
15 'title' => t('Node template'),
16 'page title' => t('Node template wizard'),
17 'description' => t('The node page wizard can help you override the node page for a type of node.'),
23 'type' => t('Select node type'),
24 'content' => t('Content'),
29 'form id' => 'panels_node_override_basic',
32 'form id' => 'panels_node_override_content',
37 'default cache' => 'panels_node_override_new_page',
39 'start' => 'panels_node_override_start',
40 'finish' => 'panels_node_override_finish',
44 * Provide defaults for a new cache.
46 * The cache will store all our temporary data; it isn't really a page
47 * in itself, but it does contain everything we need to make one at the end.
49 function panels_node_override_new_page(&$cache) {
51 $cache->display
= panels_new_display();
52 $cache->display
->layout
= 'flexible';
56 * Callback called prior to the wizard starting up on every page
59 function panels_node_override_start($form_info, $step, &$form_state) {
60 $form_state['page'] = page_manager_get_page_cache('node_view');
61 if (!empty($form_state['page']->locked
)) {
62 $account = user_load($form_state['page']->locked
->uid
);
63 $name = theme('username', array('account' => $account));
64 $lock_age = format_interval(time() - $form_state['page']->locked
->updated
);
65 $break = url(page_manager_edit_url($form_state['page']->task_name
, array('actions', 'break-lock')));
67 drupal_set_message(t('WARNING! The node_view is being edited by user !user, and is therefore locked from editing by others. This wizard cannot create a new node override while this page is locked. This lock is !age old. Click here to <a href="!break">break this lock</a>.', array('!user' => $name, '!age' => $lock_age, '!break' => $break)), 'warning');
72 * First page of our page creator wizard.
74 function panels_node_override_basic($form, &$form_state) {
75 $types = node_type_get_types();
76 $form_state['types'] = $types;
78 $already_done = array();
79 // Figure out which types already have variants assigned to them.
80 foreach ($form_state['page']->handlers as
$name => $handler) {
81 if ($handler->handler
== 'panel_context' && !empty($handler->conf
['access']['plugins'])) {
82 foreach ($handler->conf
['access']['plugins'] as
$plugin) {
83 if ($plugin['name'] == 'node_type') {
84 foreach ($plugin['settings']['type'] as
$type) {
85 $already_done[$type] = $name;
94 foreach ($already_done as
$type => $handler_id) {
95 $items[] = check_plain($types[$type]->name
) .
' ' .
l(t('[Edit]'), page_manager_edit_url($form_state['page']->task_name
, array('handlers', $handler_id, 'content')));
98 $form['already_done'] = array(
100 '#title' => t('Existing node templates'),
101 '#value' => theme('item_list', array('items' => $items)),
106 foreach ($types as
$name => $type) {
107 if (empty($already_done[$name])) {
108 $options[$name] = $type->name
;
112 $form['type'] = array(
114 '#title' => t('Node type'),
115 '#options' => $options,
116 '#default_value' => $form_state['cache']->type
,
119 ctools_include('page-wizard', 'panels');
120 panels_page_wizard_add_layout($form, $form_state);
126 * Submit function to store the form data in our cache.
128 function panels_node_override_basic_submit(&$form, &$form_state) {
129 $cache = &$form_state['cache'];
130 $cache->display
->layout
= $form_state['values']['layout'];
131 $cache->type
= $form_state['values']['type'];
133 // Create a new handler object and cache it; this way we can use the
134 // handler object for retrieving contexts properly.
135 // Create the the panel context variant configured with our display
136 $plugin = page_manager_get_task_handler('panel_context');
138 // Create a new handler.
139 $cache->handler
= page_manager_new_task_handler($plugin);
140 $cache->handler
->conf
['title'] = $form_state['types'][$cache->type
]->name
;
141 $cache->handler
->conf
['pipeline'] = 'ipe';
142 $cache->handler
->conf
['access'] = array(
145 'name' => 'node_type',
148 $cache->type
=> $cache->type
,
151 'context' => 'argument_nid_1',
158 // Find a region by trying some basic main content region IDs.
159 $layout = panels_get_layout($form_state['values']['layout']);
160 $regions = panels_get_regions($layout, $cache->display
);
161 foreach (array('center', 'middle', 'content', 'main') as
$candidate) {
162 if (!empty($regions[$candidate])) {
163 $region = $candidate;
168 // If all of the above failed, use the first region.
169 if (empty($region)) {
170 $keys = array_keys($regions);
171 $region = reset($keys);
174 // Populate the layout with content. This is from an export, with minor
175 // changes to ensure defaults are correct and to add stuff to the proper region.
176 $pane = new stdClass
;
177 $pane->pid
= 'new-1';
178 $pane->panel
= $region;
179 $pane->type
= 'node_content';
180 $pane->subtype
= 'node_content';
182 $pane->access
= array();
183 $pane->configuration
= array(
187 'override_title' => 0,
188 'override_title_text' => '',
191 'leave_node_title' => 0,
192 'context' => 'argument_nid_1',
193 'build_mode' => 'full',
195 $pane->cache
= array();
196 $pane->style
= array(
199 $pane->css
= array();
200 $pane->extras
= array();
202 $cache->display
->content
['new-1'] = $pane;
203 $cache->display
->panels
[$region][0] = 'new-1';
204 $pane = new stdClass
;
205 $pane->pid
= 'new-2';
206 $pane->panel
= $region;
207 $pane->type
= 'node_comments';
208 $pane->subtype
= 'node_comments';
210 $pane->access
= array();
211 $pane->configuration
= array(
212 'mode' => variable_get('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED
),
213 'order' => variable_get('comment_default_order', COMMENT_ORDER_NEWEST_FIRST
),
214 'comments_per_page' => variable_get('comment_default_per_page', '50'),
215 'context' => 'argument_nid_1',
216 'override_title' => 0,
217 'override_title_text' => '',
219 $pane->cache
= array();
220 $pane->style
= array(
223 $pane->css
= array();
224 $pane->extras
= array();
226 $cache->display
->content
['new-2'] = $pane;
227 $cache->display
->panels
[$region][1] = 'new-2';
228 $pane = new stdClass
;
229 $pane->pid
= 'new-3';
230 $pane->panel
= $region;
231 $pane->type
= 'node_comment_form';
232 $pane->subtype
= 'node_comment_form';
234 $pane->access
= array();
235 $pane->configuration
= array(
237 'context' => 'argument_nid_1',
238 'override_title' => 0,
239 'override_title_text' => '',
241 $pane->cache
= array();
242 $pane->style
= array(
245 $pane->css
= array();
246 $pane->extras
= array();
248 $cache->display
->content
['new-3'] = $pane;
249 $cache->display
->panels
[$region][2] = 'new-3';
251 $task = page_manager_get_task('node_view');
252 ctools_include('context');
253 ctools_include('context-task-handler');
254 $cache->context
= ctools_context_handler_get_all_contexts($task, NULL
, $cache->handler
);
259 * Second page of our wizard. This one provides a layout and lets the
262 function panels_node_override_content($form, &$form_state) {
263 ctools_include('page-wizard', 'panels');
264 panels_page_wizard_add_content($form, $form_state);
270 * Store changes to the display.
272 function panels_node_override_content_submit(&$form, &$form_state) {
273 panels_page_wizard_add_content_submit($form, $form_state);
277 * Complete the wizard, create a new variant, and send them to the
278 * edit screen of that variant.
280 function panels_node_override_finish(&$form_state) {
281 $page = &$form_state['page'];
282 $cache = &$form_state['cache'];
284 // Add the new handler to the page
285 $cache->handler
->conf
['display'] = $cache->display
;
286 page_manager_handler_add_to_page($page, $cache->handler
);
289 page_manager_save_page_cache($page);
291 // Send us to the page manager edit form for this.
292 $form_state['redirect'] = url(page_manager_edit_url('node_view', array('handlers', $cache->handler
->name
, 'content')));
293 drupal_set_message(t('Your node template has been created.'));