backdrop-contrib/reference

Upgrade path from term_reference

Opened this issue · 1 comments

  • For Backdrop sites with term_reference fields, we'll need to provide people with an opt-in to convert those term_reference fields to reference fields.

We should not do this automatically when upgrading from Drupal for two reasons: 1) The core reference module will not support referencing terms right away so there will be some time when reference is un core without term reference support, and 2) some people may prefer to keep their term referecne fields until the term_reference field type is removed from core. At that point we can require the upgrade path to reference fields.

@moonray already started on some code for the taxonomy_term_reference field upgrade path, but it was done as a part of the code that updated references module. I don't want that work to be lost, so I'm going to add it here until a PR can be created:

  elseif ($field_settings['type'] == 'taxonomy_term_reference') {
    $config = config($name);
    $settings = $config->get();

    $bundles = $field_settings['settings']['allowed_values'];
    $settings = _reference_install_update_field_instance_settings($settings, $bundles);

    // Set field formatter.
    $settings['display']['default']['module'] = 'reference';

    // If custom formatter is used, reset to default formatter.
    $settings['display']['default']['type'] = 'reference_link';
    $settings['display']['default']['settings'] = array();

    // Before saving, convert field base (we first had to move some old
    // field base settings into the instance settings).
    $field_settings = _reference_install_update_field_base_settings($field_settings, 'user');
    $field_config->setData($field_settings);
    $field_config->save();

    // Now save field instance settings.
    $config->setData($settings);
    $config->save();

    // Updated db field name.
    _reference_install_change_field($field_settings['field_name'], $field_settings['field_name'] . '_tid');
  }