Get field machine name inside HOOK_preprocess_file_link()? I am hoping to get the field name inside the HOOK_preprocess_file_link.

Only wanting to alter the link of the file for certain field names.

Hook_preprocess_field() would probably work, but would prefer to use HOOK_preprocess_file_link().

Is it possible to get the field name in this hook?



MYMODULE.module:

function HOOK_preprocess_file_link(&amp;$variables, $fieldName) {

  kpr($fieldName); // This returns "file_link" instead of the field name like "field_myfilefield".

}

function HOOK_preprocess_field(&amp;$variables) {

  if (isset($variables['field_name'])) {
    $fieldName = $variables['field_name'];
  }
  HOOK_preprocess_file_link($variables, $fieldName);

}
You need to pass the field name to the file link through hook_preprocess_field()
A similar approach is used in Themable Forms module.
Check its module file.