Index: skeleton_instance.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/skeleton/skeleton_instance.inc,v retrieving revision 1.5 diff -u -r1.5 skeleton_instance.inc --- skeleton_instance.inc 19 Dec 2008 18:17:47 -0000 1.5 +++ skeleton_instance.inc 23 Dec 2008 02:35:59 -0000 @@ -18,43 +18,13 @@ * Themed HTML, including the outline form */ function skeleton_define($skeleton) { - $output = '

'. check_plain($skeleton->skeleton) .'

'; $result = db_query("SELECT COUNT(1) FROM {skeleton_template}"); if (db_result($result) == 0) { $output .= t('

No skeleton templates are available to add to this outline. Add a skeleton template.

', array('@template-add-url' => url('admin/content/skeleton/template/add'))); return $output; } $templates = skeleton_get_tree($skeleton->skeleton_id); - - $output .= t('

Below are the current templates assigned to this skeleton outline.

'); - $output .= t('

Current templates

'); - $output .= '

'. l(t('Create new instance'), 'admin/content/skeleton/create/'. $skeleton->skeleton_id) .'

'; $output .= drupal_get_form('skeleton_define_form', $skeleton, $templates); - // show the remaining options - $remove = array(); - foreach ($templates as $i => $template) { - $remove[] = $template->template_id; - } - if (!empty($remove)) { - $result = db_query("SELECT template_id, template, node_type FROM {skeleton_template} WHERE template_id NOT IN (". implode(', ', $remove) .") ORDER BY template_id"); - } - else { - $result = db_query("SELECT template_id, template, node_type FROM {skeleton_template} ORDER BY template_id"); - } - $header = array(t('Id'), t('Name'), t('Node type'), array('data' => t('Options'), 'colspan' => 2)); - $rows = array(); - while ($template = db_fetch_object($result)) { - $link = l(t('Add template'), 'admin/content/skeleton/assign/add/'. $skeleton->skeleton_id .'/'. $template->template_id); - $rows[] = array($template->template_id, check_plain($template->template), $template->node_type, $link); - } - $output .= t('

Available templates

'); - if (!empty($rows)) { - $output .= theme('table', $header, $rows); - } - else { - $output .= t('

No skeleton templates are available to add to this outline. Add a skeleton template.

', array('@template-add-url' => url('admin/content/skeleton/template/add'))); - } - $output .= '

'. l(t('Create new template'), 'admin/content/skeleton/template/add') .'

'; return $output; } @@ -76,7 +46,7 @@ // TODO -- calculate the parent and weight correctly? db_query("INSERT INTO {skeleton_data} (skeleton_id, template_id, parent, weight) VALUES (%d, %d, %d, %d)", $skeleton->skeleton_id, $template->template_id, $parent, $weight); drupal_set_message(t('Template assigned')); - drupal_goto('admin/content/skeleton/edit/'. $skeleton->skeleton_id); + drupal_goto('admin/content/skeleton/skeleton/'. $skeleton->skeleton_id . '/edit'); } elseif ($check && $action == 'remove') { // update the children with the new parent, keep the original weight @@ -91,7 +61,7 @@ // remove db_query("DELETE FROM {skeleton_data} WHERE skeleton_id = %d AND template_id = %d", $skeleton->skeleton_id, $template->template_id); drupal_set_message(t('Template removed')); - drupal_goto('admin/content/skeleton/edit/'. $skeleton->skeleton_id); + drupal_goto('admin/content/skeleton/skeleton/'. $skeleton->skeleton_id . '/edit'); } else { return 'failed'; @@ -110,7 +80,62 @@ function skeleton_define_form($form_state, $skeleton, $templates) { $form = array(); $form['#tree'] = TRUE; - $form['skeleton_id'] = array('#type' => 'value', '#value' => $skeleton->skeleton_id); + $form['skeleton_id'] = array( + '#type' => 'value', + '#value' => $skeleton->skeleton_id, + ); + // show the remaining options + $remove = array(); + foreach ($templates as $i => $template) { + $remove[] = $template->template_id; + } + if (!empty($remove)) { + $result = db_query("SELECT template_id, template, node_type, node_data FROM {skeleton_template} WHERE template_id NOT IN (". implode(', ', $remove) .") ORDER BY template_id"); + } + else { + $result = db_query("SELECT template_id, template, node_type, node_data FROM {skeleton_template} ORDER BY template_id"); + } + while ($template = db_fetch_object($result)) { + $form['available_templates'][$template->template_id] = array( + 'template_id' => array( + '#type' => 'value', + '#value' => $template->template_id, + ), + 'template' => array( + '#value' => check_plain($template->template), + ), + 'node_type' => array( + '#value' => $template-> node_type, + ), + 'link' => array( + '#value' => l(t('Add template to skeleton'), 'admin/content/skeleton/assign/add/'. $skeleton->skeleton_id .'/'. $template->template_id), + ), + ); + if (module_exists('translation')) { + $form['multilang'] = array( + '#type' => 'value', + '#value' => TRUE, + ); + $node = (object)unserialize($template->node_data); + $form['available_templates'][$template->template_id]['language'] = array( + '#value' => locale_language_name($node->language), + ); + } + } + if (empty($form['available_templates'])) { + $form['available_templates'] = array( + '#value' => t('

No skeleton templates are available to add to this outline. Add a skeleton template.

', array('@template-add-url' => url('admin/content/skeleton/template/add'))), + ); + } + $form['available_templates']['create'] = array( + '#value' => '

'. l(t('Create new template'), 'admin/content/skeleton/template/add') .'

', + ); + + $form['current_templates']['help_text'] = array( + '#prefix' => '

', + '#suffix' => '

', + '#value' => t('Below are the current templates assigned to this skeleton outline.'), + ); foreach ($templates as $i => $template) { $options = array(0 => ''); foreach ($templates as $temp) { @@ -118,20 +143,62 @@ $options[$temp->template_id] = $temp->template; } } - $form[$i]['template_id'] = array('#type' => 'value', '#value' => $template->template_id); - $form[$i]['temp_id'] = array('#value' => $template->template_id); - $form[$i]['template'] = array('#value' => str_repeat('-', $template->depth) .' '. check_plain($template->template)); - $form[$i]['node_type'] = array('#value' => check_plain($template->node_type)); - $form[$i]['parent'] = array('#type' => 'select', + $form['current_templates'][$i]['template_id'] = array( + '#type' => 'value', + '#value' => $template->template_id, + ); + $form['current_templates'][$i]['template'] = array( + '#value' => str_repeat('-', $template->depth) .' '. check_plain($template->template), + ); + $form['current_templates'][$i]['node_type'] = array( + '#value' => check_plain($template->node_type), + ); + if (module_exists('translation')) { + $form['multilang'] = array( + '#type' => 'value', + '#value' => TRUE, + ); + $node = (object)unserialize($template->node_data); + $form['current_templates'][$i]['language'] = array( + '#value' => locale_language_name($node->language), + ); + } + $form['current_templates'][$i]['parent'] = array('#type' => 'select', '#default_value' => $template->parent, '#options' => $options, ); - $form[$i]['weight'] = array('#type' => 'weight', '#default_value' => $template->weight, '#delta' => 15); - $form[$i]['modify'] = array('#value' => l(t('edit'), 'admin/content/skeleton/template/'. $template->template_id . '/edit')); - $form[$i]['delete'] = array('#value' => l(t('remove'), 'admin/content/skeleton/assign/remove/'. $skeleton->skeleton_id .'/'. $template->template_id)); + $form['current_templates'][$i]['weight'] = array( + '#type' => 'weight', + '#default_value' => $template->weight, + '#delta' => 15 + ); + $form['current_templates'][$i]['modify'] = array( + '#value' => l(t('edit tempate'), 'admin/content/skeleton/template/'. $template->template_id . '/edit', array('query' => drupal_get_destination())), + ); + $form['current_templates'][$i]['delete'] = array( + '#value' => l(t('remove from skeleton'), 'admin/content/skeleton/assign/remove/'. $skeleton->skeleton_id .'/'. $template->template_id) + ); } - $form['notes'] = array('#value' => '

'. t('If you change a template parent, all the children of that parent will be reassigned as well.') .'

'); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save skeleton outline')); + $form['current_templates']['notes'] = array( + '#value' => '

'. t('If you change a template parent, all the children of that parent will be reassigned as well.') .'

' + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#weight' => 100, + ); + $form['create'] = array( + '#type' => 'submit', + '#value' => t('Create instance'), + '#submit' => array('skeleton_create_redirect'), + '#weight' => 150, + ); + $form['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + '#submit' => array('skeleton_delete_redirect'), + '#weight' => 200, + ); return $form; } @@ -139,7 +206,7 @@ * FormsAPI for skeleton_define() */ function skeleton_define_form_submit($form, &$form_state) { - foreach ($form_state['values'] as $key => $template) { + foreach ($form_state['values']['current_templates'] as $key => $template) { // only the numeric keys are templates, so process those if (is_numeric($key)) { db_query("UPDATE {skeleton_data} SET parent = %d, weight = %d WHERE skeleton_id = %d AND template_id = %d", $template['parent'], $template['weight'], $form_state['values']['skeleton_id'], $template['template_id']); @@ -153,29 +220,80 @@ * Formats the form in a table. */ function theme_skeleton_define_form($form) { - // Build rows + // Build current templates table. $rows = array(); - $last_region = ''; - $last_status = 1; - foreach (element_children($form) as $i) { - $template = &$form[$i]; + foreach (element_children($form['current_templates']) as $i) { + $template = &$form['current_templates'][$i]; if (isset($template['template_id'])) { - $row = array( - drupal_render($template['temp_id']), - drupal_render($template['template']), - drupal_render($template['node_type']), - drupal_render($template['parent']), - drupal_render($template['weight']), - ); - $row[] = drupal_render($template['modify']); - $row[] = drupal_render($template['delete']); - $rows[] = $row; + $row = array( + drupal_render($template['template']), + drupal_render($template['node_type']), + ); + if (!empty($form['multilang'])) { + $row[] = drupal_render($template['language']); + } + $row[] = drupal_render($template['parent']); + $row[] = drupal_render($template['weight']); + $row[] = theme('item_list', array(drupal_render($template['modify']), drupal_render($template['delete']))); + $rows[] = $row; } } - // Finish table - $header = array(t('Id'), t('Template'), t('Node type'), t('Parent'), t('Weight')); + // Finish table. + $header = array(t('Template'), t('Node type')); + if ($form['multilang']) { + $header[] = t('Language'); + } + $header[] = t('Parent'); + $header[] = t('Weight'); $header[] = array('data' => t('Operations'), 'colspan' => 2); - $output = theme('table', $header, $rows, array('id' => 'skeleton')); + $output = t('

Current templates

'); + $output .= drupal_render($form['current_templates']['help_text']); + $output .= theme('table', $header, $rows, array('id' => 'skeleton')); + + // Add anything under current_templates. + $output .= drupal_render($form['current_templates']); + + // Build available templates table. + $rows = array(); + foreach (element_children($form['available_templates']) as $i) { + $template = &$form['available_templates'][$i]; + if (isset($template['template_id'])) { + $row = array( + drupal_render($template['template']), + drupal_render($template['node_type']) + ); + if (!empty($form['multilang'])) { + $row[] = drupal_render($template['language']); + } + $row[] = theme('item_list', array(drupal_render($template['link']))); + $rows[] = $row; + } + } + + $header = array(t('Name'), t('Node type')); + if ($form['multilang']) { + $header[] = t('Language'); + } + $header[] = t('Operations'); + $output .= t('

Available templates

'); + $output .= drupal_render($form['available_templates']['help_text']); + $output .= theme('table', $header, $rows); + + // Append any additional form elements to the bottom of the form. $output .= drupal_render($form); return $output; -} \ No newline at end of file +} + +/** + * Redirect when clicking delete button on the skeleton form. + */ +function skeleton_delete_redirect($form_id, &$form_state) { + $form_state['redirect'] = 'admin/content/skeleton/skeleton/' . $form_state['values']['skeleton_id'] . '/delete'; +} + +/** + * Redirect when clicking "Create instance" on the skeleton form. + */ +function skeleton_create_redirect($form_id, &$form_state) { + $form_state['redirect'] = 'admin/content/skeleton/skeleton/'. $form_state['values']['skeleton_id'] . '/create'; +} Index: skeleton.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/skeleton/skeleton.module,v retrieving revision 1.9 diff -u -r1.9 skeleton.module --- skeleton.module 23 Dec 2008 00:26:59 -0000 1.9 +++ skeleton.module 23 Dec 2008 02:35:59 -0000 @@ -240,3 +240,17 @@ function _skeleton_user_can_view() { return user_access('configure skeleton outlines') || user_access('create new instances'); } + +/** + * Implementation of hook_theme() + */ +function skeleton_theme() { + return array( + 'skeleton_define_form' => array( + 'arguments' => array('form' => NULL), + ), + 'skeleton_na_form_element' => array( + 'arguments' => array('form' => NULL), + ), + ); +}