Update documentation for handling dots in the static_map plugin

Created on 15 November 2016, about 8 years ago
Updated 28 April 2024, 8 months ago

Problem/Motivation

Thanks to #2293773: Field allowed values use dots in key names - not allowed in config β†’ , the Drupal configuration system does not allow periods (a.k.a. "dots") to appear in any configuration key. Thus, a perfectly reasonable static_map usage to translate source strings to allowed_values:

  field_cpu_bus_type:
    plugin: static_map
    source: BusType
    bypass: true
    map:
      'PCIe 3.0': pcie_3_0
      PCI: pci

...

Fails with

exception 'Drupal\Core\Config\ConfigValueException' with message 'PCIe 3.0 key contains a dot which is not supported.' in /var/www/example/docroot/core/lib/Drupal/Core/Config/ConfigBase.php:211

Here's a thought - permit map entries to be specified such that the map key is not a YAML key but rather a YAML value. E.g.:

  field_cpu_bus_type:
    plugin: static_map
    source: BusType
    bypass: true
    map:
      -
        key: 'PCIe 3.0'
        value: pcie_3_0
      PCI: pci
...

Steps to reproduce

Proposed resolution

Add test of configuration key with a dot
Update the StaticMap documentation accordingly.

Remaining tasks

Update the patch
Review commit.

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

10.3 ✨

Component
MigrationΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mikeryan Murphysboro, IL, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • last update over 1 year ago
    29,435 pass
  • πŸ‡ΊπŸ‡ΈUnited States mikelutz Michigan, USA

    Keeping the test that shows this works, and changing the documentation in the plugin.

  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    Thanks, @danflanagan8 and @mikelutz. The patch looks good.

    Just to be sure that the test covers what we think it does, I hacked StaticMap and added

        if (is_string($value) && str_contains($value, '.')) {
          throw new MigrateException('Key contains a "." character.');
        }
    

    As expected, the test failed with my new error message.

    I am updating the title, as @quietone suggested in #21.

    I will also add an issue for the migrate_plus module.

  • last update over 1 year ago
    29,437 pass
  • last update over 1 year ago
    29,438 pass
  • last update over 1 year ago
    29,446 pass
  • last update over 1 year ago
    29,451 pass
  • last update over 1 year ago
    29,499 pass, 1 fail
  • last update over 1 year ago
    29,500 pass
  • πŸ‡ΊπŸ‡ΈUnited States mikelutz Michigan, USA

    The patch didn't fail testing, The testing failed the patch. 😐

  • last update over 1 year ago
    29,500 pass
  • last update over 1 year ago
    29,509 pass
  • last update over 1 year ago
    29,554 pass
  • last update over 1 year ago
    29,554 pass
  • Status changed to Needs work over 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone
    1. +++ b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/external_translated_test_node.yml
      @@ -15,5 +15,6 @@ process:
      +      T.B.D.: un
      
      +++ b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/external_translated_test_node_translation.yml
      @@ -19,6 +19,7 @@ process:
      +      T.B.D.: und
      

      I keep wondering why these have been changed. These test modules are not used for testing the static map plugin. I think these should be removed. Or have I missed something?

    2. +++ b/core/modules/migrate/src/Plugin/migrate/process/StaticMap.php
      @@ -133,10 +133,13 @@
      + * Note: While this plugin supports mapping from a string that contains a
      + * period, using this module with contrib modules which store migration
      + * configuration data as configuration entities will prevent this from working,
      + * as Drupal configuration entities may not contain keys which contain a period.
      + * Mapping from strings containing periods in conjunction with these contrib
      + * modules may require additional manipulation with custom or contrib process
      + * plugins.
      

      We have a pattern of adding documentation at the top of the plugin doc block, before all the examples so this should move to after the available keys section. See Substr.php.

      And since I've asked for a change we should also make this text easier to read. I had a go at using plain language as follows. This is only a suggestion.

       * This plugin supports mapping from a string that contains a dot. However, it
       * does now work when the migration is stored as a configuration entity. This is
       * because Drupal configuration entities may not contain keys which contain a
       * dot.
       * Some contributed modules convert migrations to configuration entities.
       * If you are using such a module you will need custom or contrib process
       * plugins to process the string.
      
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    Regarding @quietone's 27.1

    I keep wondering why these have been changed

    I added those changes to prove that a dot doesn't cause any problems when static map is used in yaml as opposed to simply called in a unit test. It looks like I edited those particular migrations because those are the test migrations that use static_map.

    These test modules are not used for testing the static map plugin. I think these should be removed.

    I agree with that. This is getting to be a pretty long time ago, but I don't think I ever intended for those changes to get committed. The main goal of my patches in #17 were to offer definitive proof that the problem is in migrate_plus rather than core. Using a dot in a migrate (yaml) plugin is fine, while using a dot in a migrate_plus migration config entity is not fine. I probably should have somehow indicated in the patch name that it was a "do-not-commit" patch or something. :)

    I think we could revert those changes without replacement. I don't think we typically have tests for process plugin that would use a dedicated yaml, do we? I took a quick look right now and can't find any examples.

  • Status changed to Needs review 9 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Convert to MR then made changes I suggested in #27 and @danflanagan8 agreed with in #28. I then made an attempt to simplify the new paragraph in staticmap.

  • Status changed to Needs work 9 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 8 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • First commit to issue fork.
  • Pipeline finished with Success
    8 months ago
    Total: 1298s
    #145894
  • Status changed to RTBC 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Added nitpicky change for :void to test, didn't break anything.

    Appears feedback has been addressed. Comment block reads well to me and leaning on quietone's expertise with the migration system.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I think the migrate_plus module should contain a fix for this as it is responsible for saving the static map to config. Essentially it is not be careful enough - as the comment says.

    The change here for core looks good.

    Committed and pushed 4da76f6b37 to 11.x and a1e704d78d to 10.3.x. Thanks!

    • alexpott β†’ committed a1e704d7 on 10.3.x
      Issue #2827897 by quietone, danflanagan8, mikelutz, smustgrave, mikeryan...
  • Status changed to Fixed 8 months ago
    • alexpott β†’ committed 4da76f6b on 11.x
      Issue #2827897 by quietone, danflanagan8, mikelutz, smustgrave, mikeryan...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024