Problem/Motivation

Add support for the custom_field module, so entities using that field can be exported and imported using Default Content (or Drupal core recipe importer).

Export functionality for most custom_field data types are working out of the box, but the ones referencing entities will export the entity target IDs, rather than UUIDs used by the importer.

Steps to reproduce

- Install Default Content & custom_field
- Set up a custom_field field, containing (amongst others) an image field or entity reference field.
- Try export / import functionality.

Proposed resolution

- Add support for custom_field entity references in the Normalizer class.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

svendecabooter created an issue. See original summary.

svendecabooter’s picture

Status: Active » Needs review

Created an MR that updates custom_field data in the Default Content export for referenced entities.

Original output without this MR:

field_my_custom_field:
    -
      label: 'Exported label'
      image: 21 # Some random file ID
      image__width: 1024
      image__height: 1024
      image__alt: Sunset
      image__title: ''
      file: 22 # Some random file ID
      term: 4 # Some random taxonomy term ID

After applying this MR. this becomes:

  field_my_custom_field:
    -
      label: 'Exported label'
      image: aa6340f0-0006-4f31-9f2d-5595f5cce028
      image__width: 1024
      image__height: 1024
      image__alt: Sunset
      image__title: ''
      file: c36ea199-cd17-4fe5-bec7-beef1ffb51b4
      term: 78ae1ee7-f2d4-4fc0-871e-1af92730df3b

The referenced UUIDs also get added as a dependency to the "_meta" definition.

svendecabooter’s picture

On the import side of things, there is a patch for custom_field that makes this work: #3528586: Support Drupal core DefaultContent API.

svendecabooter’s picture

svendecabooter’s picture

StatusFileSize
new1.86 KB

Attached is a patch file for the current state of the MR, useful for Composer based patching workflows.

apmsooner’s picture

@svendecabooter,

Building on my comment in https://www.drupal.org/project/custom_field/issues/3528586#comment-16166705, it might just make best sense to create a reference type base class in custom_field that those 3 types extend so that this patch here can just depend on a single class. Forward thinking here in case we were to add new similar data types in custom_field so we don't have to go back and request a change again here.

apmsooner’s picture

Status: Needs review » Needs work

This patch would put a dependency on custom_field module. Needs to just check for the class as string vs. requiring the interface.

svendecabooter’s picture

Status: Needs work » Needs review

Dependency on custom_field removed, by explicitly checking if the module is enabled.

apmsooner’s picture

phenaproxima’s picture

Core now has a default context exporter (it will be released in 11.3.0), and it is pluggable. I would suggest that custom_field integrate with that directly instead. :)

See https://www.drupal.org/node/3533854 for details.

berdir’s picture

FWIW, I don't think the importer (which this also has to integrate with) is pluggable enough yet, as we discussed the pre import event is called once for all entities. I think we should add an import event as well, others might need that as well