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']]) );
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slashrsm’s picture

Can you prepare a patch?

ahoeben’s picture

I can try

slashrsm’s picture

Status: Active » Needs review
FileSize
1.12 KB

What about this? It seems a bit more elegant to me....

ahoeben’s picture

Yes, that should work too, and I guess it is more elegant looking code (though it could be slower when there are many fields).

slashrsm’s picture

Commited. Thanks.