You are here

function _faq_shift_fields_down in Frequently Asked Questions 7

Shift fields down.

2 calls to _faq_shift_fields_down()
faq_install in ./faq.install
Implements hook_install().
faq_update_7002 in ./faq.install
Convert old-style detailed questions to new fields.

File

./faq.install, line 581
FAQ module install file.

Code

function _faq_shift_fields_down() {

  // Adjust the weight of the field so that it is above the answer (body).
  $instance = field_read_instance('node', 'field_detailed_question', 'faq');

  // Get all bundle instances.
  $instances = field_info_instances('node', 'faq');
  $body_widget_weight = $instances['body']['widget']['weight'];
  $body_default_weight = $instances['body']['display']['default']['weight'];
  $body_teaser_weight = $instances['body']['display']['teaser']['weight'];

  // Move all of them one down so that.
  foreach ($instances as $field => $settings) {
    if ($settings['widget']['weight'] >= $body_widget_weight) {
      $settings['widget']['weight']++;
    }
    if ($settings['display']['default']['weight'] >= $body_default_weight) {
      $settings['display']['default']['weight']++;
    }
    if ($settings['display']['teaser']['weight'] >= $body_teaser_weight) {
      $settings['display']['teaser']['weight']++;
    }
    field_update_instance($settings);
  }
  $instance['widget']['weight'] = $body_widget_weight;
  $instance['display']['default']['weight'] = $body_default_weight;
  $instance['display']['teaser']['weight'] = $body_teaser_weight;
  field_update_instance($instance);
}