Taxonomy term needs condition in populate batch

Created on 7 July 2025, 2 days ago

Problem/Motivation

When cloning data image_field_to_media_populate_media_field there needs to be a condition in the query to use "vid" instead of "type" for the bundle.

Steps to reproduce

Create and populate an image field on a taxonomy term.
Clone the field as a media entity.
You will get a message about "type" being invalid.

Proposed resolution

In image_field_to_media.batch.inc

function image_field_to_media_populate_media_field($entity_type_id, array $bundles, $image_field_name, $media_field_name, array &$context): void {

  if (empty($context['results']['updated_entities'])) {
    $context['results']['updated_entities'] = 0;
  }

  $counter = $context['results']['updated_entities'];
  $type_key = match ($entity_type_id) {
    'taxonomy_term' => 'vid',
    default => 'type',
  };

  $entity_id = \Drupal::entityTypeManager()->getStorage($entity_type_id)
    ->getQuery()
    ->accessCheck(TRUE)
    ->condition($type_key, $bundles, 'IN')
    ->exists($image_field_name)
    ->range($counter, 1)
    ->execute();
...

Remaining tasks

Create a patch

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Chris Dart

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024