Follow-up on #1801304: Add Entity reference field
File and Image are actually references for an entity, but we a fancy widget. We might consider converting those field types to leverage Entity-reference.

See yched's comment

Comments

Dave Reid’s picture

Dave Reid’s picture

Issue tags: +Media Initiative
Dave Reid’s picture

Title: Meta: Replace File/ Image field types with Entity-reference » Replace File and Image field types with Entity-reference
Version: 8.0.x-dev » 8.1.x-dev
Category: Task » Feature request
Issue summary: View changes

8.1.x material at this point

Berdir’s picture

file/image actually extend the entity reference field type.

And as long as the have additional properties that they need to store, that'll stay like this. I'm fairly sure that continue to be like that at least for 8.x and not something that can be changed in 8.* as it would be major API and data change. Not sure if that's even the goal (some things like width/height, definitely but things like the display flag of file fields still makes perfect sense?)

Dave Reid’s picture

Width and height should be moved to the file entity object, and not stored in the field data: #1448124: Image dimensions should be available from file_load() for images, and not stored in field data.

The other problem becomes if I reference files using an entity reference field, I cannot use any image or field formatters. There's not enough sharing between the three field types.

Berdir’s picture

Yes, as I said, width/height should definitely move away but I guess not all the other properties.

The other problem becomes if I reference files using an entity reference field, I cannot use any image or field formatters. There's not enough sharing between the three field types

Yes, but that's actually solveable now. widgets/formatters now have a method to only apply to a field type with certain configurations.. for example, we have taxonomy term specific entity reference formatters. The same would be possible for an image/file formatter although they'd be missing things the file field display/description.

So we could open an issue to make them available.

My point is that I think we've likely done as much as possible already, apart from some problems that already have or should have separate issues. And might not even need this issue anymore...

yched’s picture

Agreed with what @Berdir said :

- since this issue was opened, a lot of progress was made on unifying the things that can be (file & image classes extend e_r classes, formatters extend the same base class...)

- but they need to stay separate field types since they have additional data and behavior, as demonstrated by the specific code that still exists in the respective Item and ItemList classes.

What might be discussed IMO is : should we reduce the UI confusion by hiding File entity in the list of entity types referenceable by a plain e_r field ? Is there a use case for referencing a file through an e_r field rather than through the native File / Image fields ?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

John Pitcairn’s picture

Issue summary: View changes

What might be discussed IMO is : should we reduce the UI confusion by hiding File entity in the list of entity types referenceable by a plain e_r field ? Is there a use case for referencing a file through an e_r field rather than through the native File / Image fields ?

Yes. it might be desirable to be able to reference existing files in exactly the same manner as any other entity, without the ability to upload a file, but still display a file download link to the user.

I have exactly this use-case right now, and I think I'm gonna have to write a custom formatter, dammit. "Link to referenced entity" for an entityreference field's label formatter won't produce a link for file entities.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.