diff --git a/nodeformcols-configuration.tpl.php b/nodeformcols-configuration.tpl.php index 4aca3b4..bdaf56f 100644 --- a/nodeformcols-configuration.tpl.php +++ b/nodeformcols-configuration.tpl.php @@ -4,8 +4,7 @@ * @file * Template for the configuration table */ - -$regions = nodeformcols_form_regions(); +$regions = $element['#nodeformcols_form_regions']; ?> diff --git a/nodeformcols.admin.inc b/nodeformcols.admin.inc index a718ab8..36f2fcf 100644 --- a/nodeformcols.admin.inc +++ b/nodeformcols.admin.inc @@ -114,7 +114,7 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') $placements = nodeformscols_field_placements($type, $variant); nodeformcols_update_placements($type, $variant, $placements); - $regions = nodeformcols_form_regions(); + $regions = nodeformcols_form_regions($type); $form['type'] = array( '#type' => 'value', @@ -123,6 +123,7 @@ function nodeformcols_configuration_form($form_state, $type, $variant='default') $form['#after_build'][] = '_nodeformcols_configuration_form_after_build'; $form['conf'] = array( '#theme' => array('nodeformcols_configuration'), + '#nodeformcols_form_regions' => $regions, ); foreach ($placements as $name => $info) { @@ -201,7 +202,7 @@ function _nodeformcols_configuration_form_after_build($form) { drupal_add_js(drupal_get_path('module', 'nodeformcols') . '/js/nodeformcols.js'); drupal_add_css(drupal_get_path('module', 'nodeformcols') . '/css/nodeformcols.admin.css'); - $regions = nodeformcols_form_regions(); + $regions = nodeformcols_form_regions($form['type']['#value']); foreach ($regions as $region => $title) { if (is_array($form['conf'][$region])) { uasort($form['conf'][$region], "element_sort"); @@ -232,4 +233,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.module b/nodeformcols.module index 5db4eae..999c529 100644 --- a/nodeformcols.module +++ b/nodeformcols.module @@ -52,12 +52,15 @@ function nodeformcols_ctools_plugin_directory($module, $plugin) { } } -function nodeformcols_form_regions() { - return array( +function nodeformcols_form_regions($type) { + $regions = array( 'main' => t('Main column'), 'right' => t('Right'), 'footer' => t('Footer'), ); + + drupal_alter('nodeformcols_form_regions', $regions, $type); + return $regions; } /** @@ -65,8 +68,8 @@ function nodeformcols_form_regions() { * * @return array */ -function _nodeformscols_default_field_placements() { - return array( +function _nodeformscols_default_field_placements($content_type, $variant) { + $placements = array( 'title' => array('region' => 'main'), 'body_field' => array('region' => 'main'), 'menu' => array('region' => 'right'), @@ -77,10 +80,12 @@ function _nodeformscols_default_field_placements() { 'author' => array('region' => 'right'), 'buttons' => array('region' => NODEFORMCOLS_DEFAULT_REGION, 'weight' => 100), ); + drupal_alter('nodeformcols_default_field_placements', $placements, $content_type, $variant); + return $placements; } function nodeformscols_field_placements($content_type, $variant) { - $default = _nodeformscols_default_field_placements(); + $default = _nodeformscols_default_field_placements($content_type, $variant); if ($variant != 'default') { $default = variable_get('nodeformscols_field_placements_' . $content_type . '_default', $default); @@ -127,7 +132,7 @@ function nodeformcols_form_alter(&$form, $form_state, $form_id) { /** * Preprocess function to run ahead of other modules. */ -function template_preprocess_node_form(&$aVars) { +function nodeformcols_preprocess_node_form(&$aVars) { drupal_add_css(drupal_get_path('module', 'nodeformcols') . '/css/nodeformcols.css'); $default_region = variable_get('nodeformcols_default_region', NODEFORMCOLS_DEFAULT_REGION); @@ -135,13 +140,13 @@ function template_preprocess_node_form(&$aVars) { $class = array('node-form'); $regions = array(); - $has_elements = array(); $weight = 0; - foreach (nodeformcols_form_regions() as $name => $title) { + foreach (nodeformcols_form_regions($form['#node']->type) as $name => $title) { $regions[$name] = array( '#prefix' => '
', '#suffix' => '
', '#weight' => $weight, + '#has_elements' => FALSE, ); $weight++; } @@ -171,7 +176,7 @@ function template_preprocess_node_form(&$aVars) { $field['#collapsed'] = $p['collapsed']; } $regions[$p['region']][$key] = $field; - $has_elements[$p['region']] = TRUE; + $regions[$p['region']]['#has_elements'] = TRUE; unset($form[$key]); } else { // Set the default placement for unknown fields @@ -179,23 +184,22 @@ function template_preprocess_node_form(&$aVars) { if ($adjust_to_buttons && $regions[$default_region][$key]['#weight'] >= $placements['buttons']['weight']) { $regions[$default_region][$key]['#weight'] = $placements['buttons']['weight'] - .1; } - $has_elements[$default_region] = TRUE; + $regions[$default_region]['#has_elements'] = TRUE; unset($form[$key]); } } // Ensure that we have the footer wrapper so that // we clear the floating columns - if (empty($has_elements['footer'])) { - $has_elements['footer'] = TRUE; + if (!$regions['footer']['#has_elements']) { $regions['footer'][] = array( '#type' => 'markup', '#value' => ' ', ); } - foreach ($has_elements as $name => $has) { - if ($has) { + foreach ($regions as $name => $region) { + if ($region['#has_elements']) { $class[] = 'node-form-has-region-' . $name; $form['nodeformcols_region_' . $name] = $regions[$name]; }