I have a file reference field FileItem that has a display and description property but I want to add an extra one.

I was hoping I could just override the default widget but I can't use this to store data.

My next hope was to override the FileItem class and define the new property in schema() and propertyDefinitions() but that would mean I need a new FieldType.

I don't really want to create a new FieldType as I would need to migrate all of the data from the existing field.

  • I don't have an answer off the top of my head, but one thing you could try is extending the original class, and giving your extended class the same Field ID in the field annotation. I don't know what the result will be though - it could be an error due to redefining an existing field type. Or it could ignore your class, or it could use it instead of the original, which could then solve your problem.
    – Jaypan
    Jan 14, 2019 at 23:05
  • 2
    If both annotations are identical only the class name is different. It depends on module weight and alphabetical order which wins. You can make sure your class is set in a hook_field_info_alter(): $info['file']['class'] = '\Drupal\mymodule\...';
    – 4uk4
    Jan 15, 2019 at 7:48
  • To preserve the field data of existing fields you need an install or update hook, see drupal.stackexchange.com/questions/205747/…
    – 4uk4
    Jan 15, 2019 at 7:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.