You are here

function nodeformcols_update_placements in Node form columns 7

2 calls to nodeformcols_update_placements()
nodeformcols_configuration_form in ./nodeformcols.admin.inc
nodeformcols_configuration_form_submit in ./nodeformcols.admin.inc

File

./nodeformcols.admin.inc, line 43
Contains the admin functions for Node form columns

Code

function nodeformcols_update_placements($type, $variant, &$placements) {
  $form = _nodeformcols_get_node_type_form($type);
  drupal_alter('nodeformcols_base_form', $form, $variant);
  $default_region = variable_get('nodeformcols_default_region', NODEFORMCOLS_DEFAULT_REGION);
  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['#group']) && $field['#group'] == 'additional_settings') {

      // Remove placements that meet exclusion rules.
      if (isset($placements[$key])) {
        unset($placements[$key]);
      }
      continue;
    }

    // Ensure a weight so that we don't have to worry about it later
    $field['#weight'] = isset($field['#weight']) ? $field['#weight'] : 0;
    if (!isset($placements[$key])) {

      // If the element is unknown we'll add it to
      // the field placement list
      $placements[$key] = array(
        'region' => $default_region,
        'weight' => $field['#weight'],
      );

      // Make sure that we don't auto-place the field below the buttons.
      if ($placements['actions']['region'] == $default_region && $placements[$key]['weight'] >= $placements['actions']['weight']) {
        $placements[$key]['weight'] = $placements['actions']['weight'] - 0.1;
      }
    }
    elseif (!isset($placements[$key]['weight'])) {
      $placements[$key]['weight'] = $field['#weight'];
    }
    $placements[$key]['has_required'] = _nodeformcols_has_required($field);

    // Get the element title
    $placements[$key]['title'] = _nodeformcols_get_element_title($field);
    if (isset($field['#collapsible']) && $field['#collapsible']) {
      if (!isset($placements[$key]['collapsed'])) {
        $placements[$key]['collapsed'] = isset($field['#collapsed']) && $field['#collapsed'];
      }
    }
    else {
      unset($placements[$key]['collapsed']);
    }
  }

  // Remove fields that have disappeared from
  // the placements list.
  foreach ($placements as $key => $info) {
    if (!isset($form[$key])) {
      unset($placements[$key]);
    }
  }
}