Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291936

Migrating reference fields: target_bundles may never be empty array

$
0
0

Problem/Motivation

Discovered via #2814953: Migrate Drupal 7 node/user reference fields, but is a long pre-existing bug.

#2814953-96: Migrate Drupal 7 node/user reference fields contains:

+++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
@@ -65,6 +65,43 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+        'target_bundles' => array_filter($field_data['settings']['referenceable_types'] ?? []),

Yet … field_field_config_presave() does this:

  // In case we removed all the target bundles allowed by the field in
  // EntityReferenceItem::onDependencyRemoval() or field_entity_bundle_delete()
  // we have to log a critical message because the field will not function
  // correctly anymore.
  $handler_settings = $field->getSetting('handler_settings');
  if (isset($handler_settings['target_bundles']) && $handler_settings['target_bundles'] === []) {
    \Drupal::logger('entity_reference')->critical('The %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [
      '%field_name' => $field->getName(),
      '%entity_type' => $field->getTargetEntityTypeId(),
      '%bundle' => $field->getTargetBundle(),
    ]);
  }

IOW, target_bundles must either be NULL or if it's an array, it must be non-empty. Otherwise all references will be refused!

Steps to reproduce

node_reference field without referenceable_types setting triggers something like this during the migration:

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 291936

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>