You are here

function _slick_fields_update_formatter in Slick Carousel 7.3

Helper function to update formatter type, executed once.

@todo use batch for potential large scale slicks.

2 calls to _slick_fields_update_formatter()
slick_fields_update_7300 in slick_fields/slick_fields.install
Update and replace the old Slick 2.x file/ image formatters to Slick 3.x.
slick_fields_update_7301 in slick_fields/slick_fields.install
Update and replace the old Slick 2.x entity formatters to Slick 3.x.

File

slick_fields/slick_fields.install, line 13
Installation actions for Slick fields.

Code

function _slick_fields_update_formatter($type = 'image') {
  module_load_include('inc', 'slick', 'includes/slick.update');
  $instances = [];
  $fields = field_read_fields([
    'type' => $type,
  ], [
    'include_inactive' => TRUE,
  ]);

  // Bail out if no $fields, likely installed but no fields found.
  if (empty($fields)) {
    return;
  }
  foreach ($fields as $field) {
    $instances = array_merge($instances, field_read_instances([
      'field_id' => $field['id'],
    ], [
      'include_inactive' => TRUE,
    ]));
  }

  // Bail out if no $instances, likely installed but no $instances found.
  if (empty($instances)) {
    return;
  }
  foreach ($instances as $instance) {
    $update_instance = FALSE;
    foreach ($instance['display'] as $view_mode => $display) {

      // Changed deprecated formatter into the new one based on classes.
      if ($display['type'] == 'slick') {
        $update_instance = TRUE;
        $instance['display'][$view_mode]['type'] = 'slick_' . $type;
        _slick_update_formatter_settings($instance['display'][$view_mode]['settings']);
      }
    }
    if ($update_instance) {
      field_update_instance($instance);
    }
  }
}