Problem/Motivation

Chosen doesn't have migration path from Drupal 7 to Drupal 9+.

Proposed resolution

Implement migration path from Drupal 7 to Drupal 9+.

Remaining tasks

  1. Migrate D7 Chosen settings to D9+
  2. Map D7 chosen field widgets to D9+

User interface changes

Nothing.

API changes

New migrate process plugin that maps d7 chosen field widget configs to the D9+ Chosen field widget plugin ID.

Data model changes

Nothing.

Comments

yash.rode created an issue. See original summary.

yash.rode’s picture

Status: Needs work » Needs review
StatusFileSize
new34.65 KB

Migration for Chosen.

Status: Needs review » Needs work

The last submitted patch, 2: chosen_Migrate_chosen_from_D7_to_D9-3274968-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

yash.rode’s picture

StatusFileSize
new34.61 KB
new504 bytes
huzooka’s picture

  1. +++ b/chosen.module
    @@ -150,3 +153,18 @@ function chosen_help($route_name, RouteMatchInterface $route_match) {
    +function chosen_migration_plugins_alter(array &$migrations) {
    +  $chosen_migration = array_filter(
    +    $migrations,
    +    function ($definition) {
    +      return $definition['id'] === 'd7_field_instance_widget_settings';
    +    }
    +  );
    +  foreach (array_keys($chosen_migration) as $plugin_id) {
    +    $migrations[$plugin_id]['process']['options/type'][] = ['plugin' => 'chosen'];
    +  }
    +}
    

    We need our usual check whether the chosen module is enabled on the source.

    If it isn't, then we shouldn't migrate its settings, nor modify the field widget settings migration.

  2. +++ b/migrations/d7_chosen_settings.yml
    @@ -0,0 +1,38 @@
    +  plugin: variable
    +  variables:
    +    - chosen_minimum_single
    +    - chosen_minimum_multiple
    +    - chosen_disable_search_threshold
    +    - chosen_minimum_width
    +    - chosen_jquery_selector
    +    - chosen_search_contains
    +    - chosen_disable_search
    +    - chosen_include
    +    - chosen_allow_single_deselect
    +    - chosen_placeholder_text_multiple
    +    - chosen_placeholder_text_single
    +    - chosen_no_results_text
    +    - chosen_disabled_themes
    

    It would be nice to add the source_module: chosen configuration here.

  3. +++ b/migrations/d7_chosen_settings.yml
    @@ -0,0 +1,38 @@
    +  minimum_single: chosen_minimum_single
    

    We have to properly handle the default values here:

    I checked only chosen_minimum_single: Its default value in Drupal 7 is 20 (and it can be configured to be (int) 0, so this process plugin should be:

    minimum_single:
      plugin: default_value
      source: chosen_minimum_single
      strict: true
      default_value: 20
    

    Please check the other Drupal 7 variables as well, and update the process pipeline accordingly!

  4. +++ b/src/Plugin/migrate/process/Chosen.php
    @@ -0,0 +1,29 @@
    +class Chosen extends ProcessPluginBase {
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    +    if ($value !== 'options_select' || empty($row->getSourceProperty('widget/settings/apply_chosen'))) {
    +      return $value;
    +    }
    +    return 'chosen_select';
    +  }
    +
    +}
    

    👍 Very elegant and clear!

yash.rode’s picture

Status: Needs work » Needs review
StatusFileSize
new36.92 KB
new4.6 KB

follow up for #5

huzooka’s picture

Status: Needs review » Needs work

I still have to nits (and I'm very sorry I didn't notice them before).
But other than that, #6 is perfect!

  1. +++ b/chosen.module
    @@ -7,10 +7,16 @@
    +use Drupal\migrate\Plugin\MigrateSourceInterface;
    +use Drupal\migrate\Plugin\MigrationInterface;
    +use Drupal\migrate\Row;
    

    These classes aren't used.

  2. +++ b/tests/src/Kernel/ChosenMigrationTest.php
    @@ -0,0 +1,86 @@
    +  /**
    +   * Tests Chosen data and field widget migration.
    +   */
    +  public function testFocalPointMigration(): void {
    

    This test method should be renamed!

yash.rode’s picture

Status: Needs work » Needs review
StatusFileSize
new36.8 KB
new1.01 KB

follow up for #7.

huzooka’s picture

Re @nagy.balint, I don't think so. This migration path consists of only:

  • A migration YAML that migrates D7 settings to D9, and
  • A hook_migration_plugins_alter() implementation and a migrate process plugin which migrate the right form widget for the fields which are using Chosen in the source Drupal 7 instance.

The bulk of the patch is a Drupal 7 database fixture and a migration test that uses that fixture to prove it works as expected.

If you check the modules you mentioned, they have a huge codebase. Chosen's situation is much simpler imho. https://git.drupalcode.org/project/address/-/tree/8.x-1.x/src/Plugin/mig...

Re #8:
This is now perfect! 🥳

huzooka’s picture

Issue summary: View changes
nagy.balint’s picture

Shouldnt it be a sub module the very least?

nagy.balint’s picture

After further research, it seems that its only me who finds it weird to have these in the main module.

So then I can commit it.

nagy.balint’s picture

Status: Needs review » Fixed

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.