Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The field_presave events lets the user select which fields to act on. This functionality currently does not work, causing all fields to be processed.
The problem lies in the $preset->events_settings['field_presave_allowed_fields'] array, which has a key for all listed fields, whether they are enabled or not. The value for this key is (integer)0 or (string)[field_name], so a solution is to check if the value is indeed a string.
function _media_derivatives_field_presave_validation($file, $preset, $context) {
return (in_array($context['field'], $preset->events_settings['field_presave_allowed_fields']) &&
is_string($preset->events_settings['field_presave_allowed_fields'][$context['field']]) );
}
Comment | File | Size | Author |
---|---|---|---|
#3 | media_derivatives__field_presave_processes_all_fields__1645270__2.patch | 1.12 KB | slashrsm |
#2 | _field_presave_validation fix.patch | 1.3 KB | ahoeben |
Comments
Comment #1
slashrsm CreditAttribution: slashrsm commentedCan you prepare a patch?
Comment #2
ahoeben CreditAttribution: ahoeben commentedI can try
Comment #3
slashrsm CreditAttribution: slashrsm commentedWhat about this? It seems a bit more elegant to me....
Comment #4
ahoeben CreditAttribution: ahoeben commentedYes, that should work too, and I guess it is more elegant looking code (though it could be slower when there are many fields).
Comment #5
slashrsm CreditAttribution: slashrsm commentedCommited. Thanks.