diff --git a/js/nodeformcols.js b/js/nodeformcols.js index 68ed2e3..98ce5ca 100644 --- a/js/nodeformcols.js +++ b/js/nodeformcols.js @@ -6,7 +6,9 @@ * This behavior is dependent on the tableDrag behavior, since it uses the * objects initialized in that behavior to update the row. */ -Drupal.behaviors.fieldDrag = function(context) { +(function($) { +Drupal.behaviors.fieldDrag = {}; +Drupal.behaviors.fieldDrag.attach = function(context) { var table = $('table#fields'); var tableDrag = Drupal.tableDrag.fields; // Get the fields tableDrag object. @@ -15,11 +17,6 @@ Drupal.behaviors.fieldDrag = function(context) { checkEmptyRegions(table, this); }; - // A custom message for the fields page specifically. - Drupal.theme.tableDragChangedWarning = function () { - return '
' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("The changes to these fields will not be saved until the Save fields button is clicked.") + '
'; - }; - // Add a handler so when a row is dropped, update fields dropped into new regions. tableDrag.onDrop = function() { dragObject = this; @@ -93,3 +90,4 @@ Drupal.behaviors.fieldDrag = function(context) { }); }; }; +} (jQuery)); diff --git a/nfcbiblio.info b/nfcbiblio.info index ebae011..c28d7e0 100644 --- a/nfcbiblio.info +++ b/nfcbiblio.info @@ -3,5 +3,5 @@ name = Biblio compatability description = Adds support for biblio fields dependencies[] = nodeformcols dependencies[] = biblio -core = 6.x +core = 7.x package = Node form columns diff --git a/nfcbiblio.module b/nfcbiblio.module index d69f511..93793f9 100644 --- a/nfcbiblio.module +++ b/nfcbiblio.module @@ -2,7 +2,7 @@ // $Id$ /** - * Implementation of hook_nodeformcols_variants_alter(). + * Implements hook_nodeformcols_variants_alter(). * * Implement this hook to supply information about form variants that can be * configured. @@ -17,9 +17,9 @@ function nfcbiblio_nodeformcols_variants_alter(&$variants, $type) { if ($type == 'biblio') { $res = db_query('SELECT tid, name FROM {biblio_types} - WHERE tid >= 0 - AND visible = 1 - ORDER BY weight ASC'); + WHERE tid >= :tid + AND visible = :visible + ORDER BY weight ASC', array(':tid' => 0, ':visible' => 1)); while ($option = db_fetch_object($res)) { $variants[$option->tid] = $option->name; } @@ -33,15 +33,15 @@ function nfcbiblio_nodeformcols_variants_alter(&$variants, $type) { * The id of a default biblio type */ function _nfcbiblio_top_visible_type() { - return db_result(db_query_range("SELECT tid + return db_query_range("SELECT tid FROM {biblio_types} - WHERE visible = 1 - AND tid>=0 - ORDER BY weight ASC", 0, 1)); + WHERE visible = :visible + AND tid> = :tid> + ORDER BY weight ASC", array(':visible' => 1, ':tid>' => 0))->fetchField(); } /** - * Implementation of hook_nodeformcols_pre_form_alter(). + * Implements hook_nodeformcols_pre_form_alter(). * * Implement this hook to tell nodeformcols what variant the form is before * any alterations to the form is made. @@ -59,7 +59,7 @@ function nfcbiblio_nodeformcols_pre_form_alter(&$form) { } /** - * Implementation of hook_nodeformcols_base_form_alter(). + * Implements hook_nodeformcols_base_form_alter(). * * Implement this hook if you want to alter the node creation form that * nodeformcols uses to construct the configuration interface before @@ -79,8 +79,8 @@ function nfcbiblio_nodeformcols_base_form_alter(&$form, $variant) { $biblio_form_state = array(); $biblio_form_state['post']['biblio_type'] = $variant; - foreach(biblio_form($form['#node'], $biblio_form_state) as $name => $def) { + foreach (biblio_form($form['#node'], $biblio_form_state) as $name => $def) { $form[$name] = $def; } } -} \ No newline at end of file +} diff --git a/nfccaptcha.info b/nfccaptcha.info index 29911c9..953a653 100644 --- a/nfccaptcha.info +++ b/nfccaptcha.info @@ -3,5 +3,5 @@ name = CAPTCHA compatability description = Adds support for CAPTCHA in node forms dependencies[] = nodeformcols dependencies[] = captcha -core = 6.x +core = 7.x package = Node form columns diff --git a/nfccaptcha.module b/nfccaptcha.module index d101e6e..1adb489 100644 --- a/nfccaptcha.module +++ b/nfccaptcha.module @@ -15,14 +15,14 @@ * @return void */ function nodeformcols_nodeformcols_base_form_alter(&$form, $variant) { - $using_captcha = db_result(db_query("SELECT COUNT(module) - FROM {captcha_points} WHERE form_id = '%s'", array( + $using_captcha = db_query("SELECT COUNT(module) + FROM {captcha_points} WHERE form_id = :form_id", array(':form_id' => array( ':form_id' => $form['#node']->type . '_node_form', - ))); + )))->fetchField(); if ($using_captcha) { $form['captcha'] = array( '#title' => t('CAPTCHA'), '#weight' => $form['buttons']['#weight'] - 1, ); } -} \ No newline at end of file +} diff --git a/node-form.tpl.php b/node-form.tpl.php index ac669e0..1934a7d 100644 --- a/node-form.tpl.php +++ b/node-form.tpl.php @@ -7,5 +7,5 @@ */ ?>
- +
\ No newline at end of file diff --git a/nodeformcols-configuration.tpl.php b/nodeformcols-configuration.tpl.php index 216499b..117bd21 100644 --- a/nodeformcols-configuration.tpl.php +++ b/nodeformcols-configuration.tpl.php @@ -36,10 +36,10 @@ diff --git a/nodeformcols.admin.inc b/nodeformcols.admin.inc index 7052fee..a9df156 100644 --- a/nodeformcols.admin.inc +++ b/nodeformcols.admin.inc @@ -9,10 +9,18 @@ function _nodeformcols_get_node_type_form($type) { module_load_include('inc', 'node', 'node.pages'); - $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => ''); + global $user; + $node = new stdClass(); + $node->uid = $user->uid; + $node->name = isset($user->name) ? $user->name : ''; + $node->type = $type; + $node->language = ''; $nfid = $type . '_node_form'; - $fs = array('storage' => NULL, 'submitted' => FALSE); - $nf = drupal_retrieve_form($nfid, $fs, $node); + $fs = array( + 'build_info' => array('args' => array($node)), + ); + $fs += form_state_defaults(); + $nf = drupal_retrieve_form($nfid, $fs); drupal_prepare_form($nfid, $nf, $fs); drupal_process_form($nfid, $nf, $fs); return $nf; @@ -23,9 +31,17 @@ function nodeformcols_update_placements($type, $variant, &$placements) { drupal_alter('nodeformcols_base_form', $form, $variant); $default_region = variable_get('nodeformcols_default_region', NODEFORMCOLS_DEFAULT_REGION); - foreach ($form as $key => $field) { - if (substr($key, 0, 1) == '#' || substr($key, 0, 8) == 'section_' || - $field['#type']=='value' || $field['#type']=='hidden'|| $field['#type']=='token') { + foreach (element_children($form) as $key) { + $field = $form[$key]; + if ( + substr($key, 0, 8) == 'section_' || + (isset($field['#type']) && in_array($field['#type'], array('value', 'hidden', 'token'))) || + (isset($field['#type'], $field['#group']) && $field['#type'] === 'fieldset') + ) { + // Remove placements that meet exclusion rules. + if (isset($placements[$key])) { + unset($placements[$key]); + } continue; } @@ -40,8 +56,8 @@ function nodeformcols_update_placements($type, $variant, &$placements) { 'weight' => $field['#weight'], ); // Make sure that we don't auto-place the field below the buttons. - if ($placements['buttons']['region'] == $default_region && $placements[$key]['weight'] >= $placements['buttons']['weight']) { - $placements[$key]['weight'] = $placements['buttons']['weight'] - .1; + if ($placements['actions']['region'] == $default_region && $placements[$key]['weight'] >= $placements['actions']['weight']) { + $placements[$key]['weight'] = $placements['actions']['weight'] - .1; } } elseif (!isset($placements[$key]['weight'])) { @@ -76,12 +92,21 @@ function _nodeformcols_get_element_title($element) { if (!empty($element['#title'])) { return $element['#title']; } - if ($element['#type']=='submit') { + if (isset($element['#type']) && $element['#type'] == 'submit') { return $element['#value']; } + if (isset($element['#type']) && $element['#type'] == 'vertical_tabs') { + return t('Vertical tabs'); + } + foreach (element_children($element) as $key) { + if ($title = _nodeformcols_get_element_title($element[$key])) { + return $title; + } + } } -function nodeformcols_configuration_form($form_state, $type, $variant='default') { +function nodeformcols_configuration_form($form, $form_state, $node_type, $variant = 'default') { + $type = $node_type->type; $variants = array(); drupal_alter('nodeformcols_variants', $variants, $type); @@ -90,20 +115,20 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') $variant_links = array( 'default' => array( 'title' => t('Default'), - 'href' => 'admin/content/node-type/'. $type .'/form', + 'href' => 'admin/structure/types/manage/' . $type . '/form', ), ); foreach ($variants as $id => $title) { $variant_links[] = array( 'title' => $title, - 'href' => 'admin/content/node-type/'. $type .'/form/' . $id, + 'href' => 'admin/structure/types/manage/' . $type . '/form/' . $id, ); } $form['variant'] = array( '#type' => 'item', '#title' => t('Select a form variant'), - '#value' => theme('links', $variant_links), + '#value' => theme('links', array('links' => $variant_links)), ); } @@ -132,15 +157,14 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') $form['conf'][$info['region']][$key] = array( '#weight' => $weight, $key . '_name' => array( - '#type' => 'markup', - '#value' => !empty($info['title']) ? $info['title'] : $name, + '#markup' => !empty($info['title']) ? $info['title'] : $name, ), $key . '_region' => array( '#type' => 'select', '#options' => $regions, '#default_value' => $info['region'], '#attributes' => array( - 'class' => 'field-region-select field-region-'. $info['region'], + 'class' => array('field-region-select field-region-' . $info['region']), ), ), $key . '_weight' => array( @@ -148,7 +172,7 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') '#default_value' => $weight, '#size' => 3, '#attributes' => array( - 'class' => 'field-weight field-weight-'. $info['region'], + 'class' => array('field-weight field-weight-' . $info['region']), ), ), ); @@ -157,7 +181,7 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') $form['conf'][$info['region']][$key][$key . '_hidden'] = array( '#type' => 'checkbox', '#title' => t('Hide'), - '#default_value' => $info['hidden'], + '#default_value' => isset($info['hidden']) ? $info['hidden'] : FALSE, ); } @@ -165,7 +189,7 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') $form['conf'][$info['region']][$key][$key . '_collapsed'] = array( '#type' => 'checkbox', '#title' => t('Show collapsed'), - '#default_value' => $info['collapsed'], + '#default_value' => isset($info['collapsed']) ? $info['collapsed'] : FALSE, ); } } @@ -204,11 +228,11 @@ function _nodeformcols_configuration_form_after_build($form) { $regions = nodeformcols_form_regions(); foreach ($regions as $region => $title) { - if (is_array($form['conf'][$region])) { + if (isset($form['conf'][$region]) && is_array($form['conf'][$region])) { uasort($form['conf'][$region], "element_sort"); } - drupal_add_tabledrag('fields', 'match', 'sibling', 'field-region-select', 'field-region-'. $region, NULL, FALSE); - drupal_add_tabledrag('fields', 'order', 'sibling', 'field-weight', 'field-weight-'. $region); + drupal_add_tabledrag('fields', 'match', 'sibling', 'field-region-select', 'field-region-' . $region, NULL, FALSE); + drupal_add_tabledrag('fields', 'order', 'sibling', 'field-weight', 'field-weight-' . $region); } return $form; } @@ -233,4 +257,4 @@ function nodeformcols_configuration_form_submit($form, $form_state) { variable_set('nodeformscols_field_placements_' . $type . '_' . $form['#variant'], $placements); -} \ No newline at end of file +} diff --git a/nodeformcols.info b/nodeformcols.info index 1f0644b..5c2c517 100644 --- a/nodeformcols.info +++ b/nodeformcols.info @@ -1,5 +1,5 @@ ; $Id$ name = Node form columns description = Separates the node forms into two columns and a footer. -core = 6.x +core = 7.x package = Node form columns diff --git a/nodeformcols.install b/nodeformcols.install index e82b377..7484eee 100644 --- a/nodeformcols.install +++ b/nodeformcols.install @@ -11,53 +11,22 @@ */ function nodeformcols_install() { // We need our hook_theme() to run after node.module's hook_theme(). - db_query("UPDATE {system} SET weight = %d WHERE name = '%s' AND type = '%s'", 1, 'nodeformcols', 'module'); + db_update('system') + ->fields(array('weight' => 1)) + ->condition('name', 'nodeformcols') + ->condition('type', 'module') + ->execute(); } /** * Implementation of hook_uninstall(). */ function nodeformcols_uninstall() { - $res = db_query("SELECT name FROM {variable} WHERE name LIKE 'nodeformscols_field_placements_%'"); - while ($v = db_fetch_object($res)) { + $res = db_select('variable') + ->fields('variable', array('name')) + ->condition('name', 'nodeformscols_field_placements_%', 'LIKE') + ->execute(); + foreach ($res as $v) { variable_del($v->name); } } - -/** - * Updates the old-style placements that only defined region - * to the new-style that can specify weight and collapsed state. - * - * @return void - */ -function nodeformcols_update_1() { - $ret = array(); - $res = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'nodeformscols_field_placements_%'"); - while ($v = db_fetch_object($res)) { - $placements = unserialize($v->value); - if ($placements) { - foreach ($placements as $key => $opt) { - if (!is_array($opt)) { - $placements[$key] = array('region' => $opt); - } - } - - $result = db_query("UPDATE {variable} SET value='%s' WHERE name='%s'", array( - ':value' => serialize($placements), - ':name' => $v->name, - )); - $ret[] = array('success' => $result !== FALSE, 'query' => check_plain('Updated the variable ' . $v->name)); - } - } - cache_clear_all('variables', 'cache'); - return $ret; -} - -function nodeformcols_update_6100() { - db_query("UPDATE {variable} SET name = CONCAT(name, '_default') WHERE name LIKE 'nodeformscols_field_placements_%'"); - cache_clear_all('variables','cache'); - return array(array( - 'success' => TRUE, - 'query' => 'Renamed nodeformcol variables', - )); -} diff --git a/nodeformcols.module b/nodeformcols.module index 21a27b0..763a9d5 100644 --- a/nodeformcols.module +++ b/nodeformcols.module @@ -10,11 +10,12 @@ function nodeformcols_theme($aExisting) { // This needs to run after node.module's hook_theme(), which we ensure // by setting this module's weight to 1 during install. 'node_form' => array( + 'render element' => 'form', 'template' => 'node-form', ), 'nodeformcols_configuration' => array( + 'render element' => 'element', 'template' => 'nodeformcols-configuration', - 'arguments' => array('element' => array()), ), ); } @@ -26,19 +27,15 @@ function nodeformcols_menu() { $items = array(); if (!defined('MAINTENANCE_MODE')) { - foreach (node_get_types() as $type) { - $type_name = $type->type; - $type_url_str = str_replace('_', '-', $type_name); - $items['admin/content/node-type/'. $type_url_str .'/form'] = array( - 'title' => 'Manage form', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('nodeformcols_configuration_form', $type_name, 5), - 'access arguments' => array('administer content types'), - 'file' => 'nodeformcols.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 3 - ); - } + $items['admin/structure/types/manage/%node_type/form'] = array( + 'title' => 'Manage form', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('nodeformcols_configuration_form', 4, 6), + 'access arguments' => array('administer content types'), + 'file' => 'nodeformcols.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 3, + ); } return $items; @@ -69,14 +66,8 @@ function nodeformcols_form_regions() { function _nodeformscols_default_field_placements() { return array( 'title' => array('region' => 'main'), - 'body_field' => array('region' => 'main'), - 'menu' => array('region' => 'right'), - 'revision_information' => array('region' => 'right'), - 'comment_settings' => array('region' => 'right'), - 'path' => array('region' => 'right'), - 'options' => array('region' => 'right'), - 'author' => array('region' => 'right'), - 'buttons' => array('region' => NODEFORMCOLS_DEFAULT_REGION, 'weight' => 100), + 'additional_settings' => array('region' => 'main'), + 'actions' => array('region' => NODEFORMCOLS_DEFAULT_REGION, 'weight' => 100), ); } @@ -93,26 +84,11 @@ function nodeformscols_field_placements($content_type, $variant) { return $placements; } -function nodeformscols_content_extra_fields($type_name, $variant) { - return array( - 'buttons' => array( - '#title' => t('Buttons'), - '#description' => t('Save, preview and delete buttons.'), - '#weight' => 50, - ), - 'options' => array( - '#title' => t('Workflow options'), - '#description' => t('Options for publishing, sticky and publish on front page.'), - '#weight' => 0, - ), - ); -} - /** * Implementation of hook_form_alter(). */ function nodeformcols_form_alter(&$form, $form_state, $form_id) { - if ('node-form' == $form['#id']) { + if (isset($form['#id']) && $form['#id']=='node-form') { drupal_alter('nodeformcols_pre_form', $form); $variant = isset($form['#nodeformcols_variant']) ? $form['#nodeformcols_variant'] : 'default'; $placements = nodeformscols_field_placements($form['#node']->type, $variant); @@ -133,7 +109,7 @@ function template_preprocess_node_form(&$aVars) { $default_region = variable_get('nodeformcols_default_region', NODEFORMCOLS_DEFAULT_REGION); $form = &$aVars['form']; - $class = array('node-form'); + $class = array('node-form', 'clearfix'); $regions = array(); $has_elements = array(); @@ -153,11 +129,12 @@ function template_preprocess_node_form(&$aVars) { // Track if new fields should be adjusted above the buttons. // TODO: This should be generalized to a way to tell nodeformcols where to place new fields (above below field X). - $adjust_to_buttons = $placements['buttons']['region'] == $default_region; + $adjust_to_buttons = isset($placements['buttons']['region']) && ($placements['buttons']['region'] == $default_region); - foreach ($form as $key => $field) { - if (substr($key, 0, 1)=='#' || - $field['#type']=='value' || $field['#type']=='hidden'|| $field['#type']=='token') { + foreach (element_children($form) as $key) { + $field = $form[$key]; + if (isset($field['#type']) && in_array($field['#type'], array('value', 'hidden', 'token')) || + (isset($field['#access']) && $field['#access'] == FALSE)) { continue; } @@ -184,16 +161,6 @@ function template_preprocess_node_form(&$aVars) { } } - // Ensure that we have the footer wrapper so that - // we clear the floating columns - if (!$has_elements['footer']) { - $has_elements['footer'] = TRUE; - $regions['footer'][] = array( - '#type' => 'markup', - '#value' => ' ', - ); - } - foreach ($has_elements as $name => $has) { if ($has) { $class[] = 'node-form-has-region-' . $name; @@ -205,32 +172,34 @@ function template_preprocess_node_form(&$aVars) { } /** - * Implementation of hook_node_type(). + * Implementation of hook_node_type_delete(). */ -function nodeformcols_node_type($op, $info) { - switch ($op) { - case 'delete': - db_query("DELETE FROM {variable} WHERE name LIKE '%s'", array( - ':name' => 'nodeformscols_field_placements_'. $info->type . '%', - )); - break; - case 'update': - if (!empty($info->old_type) && $info->old_type != $info->type) { - $base = 'nodeformscols_field_placements_'. $info->old_type; - $new_base = 'nodeformscols_field_placements_'. $info->type; - $res = db_query("SELECT name FROM {variable} WHERE name LIKE '%s'", array( - ':name' => $base . '%', - )); - - while ($old_name = db_result($res)) { - $new_name = str_replace($base, $new_base, $old_name); - db_query("UPDATE {variable} SET name='%s' WHERE name='%s'", array( - ':new' => $new_name, - ':old' => $old_name, - )); - } - cache_clear_all('variables', 'cache'); - } - break; +function nodeformcols_node_type_delete($info) { + $result = db_select('variable') + ->condition('name', 'nodeformscols_field_placements_' . $info->old_type . '%', 'LIKE') + ->fields('variable', array('name')) + ->execute(); + foreach ($result as $row) { + variable_del($row->name); + } +} + +/** + * Implementation of hook_node_type_update(). + */ +function nodeformcols_node_type_update($info) { + if (!empty($info->old_type) && $info->old_type != $info->type) { + $base = 'nodeformscols_field_placements_' . $info->old_type; + $new_base = 'nodeformscols_field_placements_' . $info->type; + $result = db_select('variable') + ->condition('name', $base . '%', 'LIKE') + ->fields('variable', array('name')) + ->execute(); + foreach ($result as $row) { + $value = variable_get($row->name, NULL); + $new_name = str_replace($base, $new_base, $row->name); + variable_set($new_name, $value); + variable_del($row->name); + } } } diff --git a/plugins/content_types/nodeformcols.inc b/plugins/content_types/nodeformcols.inc index e3a21ad..fb13c2f 100644 --- a/plugins/content_types/nodeformcols.inc +++ b/plugins/content_types/nodeformcols.inc @@ -70,7 +70,7 @@ function nodeformcols_nodeformcols_content_type_admin_info($subtype, $conf) { $block = new stdClass(); $block->title = t('Affected forms'); - $types = node_get_types(); + $types = node_type_get_types(); $forms = array(); foreach ($types as $type => $description) { if (variable_get('nodeformscols_field_placements_' . $type . '_default', FALSE)) { @@ -79,10 +79,10 @@ function nodeformcols_nodeformcols_content_type_admin_info($subtype, $conf) { } if (!empty($forms)) { - $block->content = theme('item_list', $forms); + $block->content = theme('item_list', array('items' => $forms)); } else { - $block->content = '

'. t('No forms are using customized nodeformcols settings.') .'

'; + $block->content = '

' . t('No forms are using customized nodeformcols settings.') . '

'; } return $block; }