function media_post_update_remove_mappings_targeting_source_field

Make sure no Media types are using the source field in the meta mappings.

File

core/modules/media/media.post_update.php, line 53

Code

function media_post_update_remove_mappings_targeting_source_field(?array &$sandbox = NULL) : void {
    \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'media_type', function (MediaTypeInterface $media_type) : bool {
        $source_field = $media_type->getSource()
            ->getSourceFieldDefinition($media_type);
        if ($source_field) {
            $source_field_name = $source_field->getName();
            $original_field_map = $media_type->getFieldMap();
            $field_map = array_diff($original_field_map, [
                $source_field_name,
            ]);
            // Check if old field map matches new field map.
            if (empty(array_diff($original_field_map, $field_map))) {
                return FALSE;
            }
            $media_type->setFieldMap($field_map);
            return TRUE;
        }
        return FALSE;
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.