Currently, there is no option to insert images from a file field. The only options are to link to file. In Drupal 7, there was the option to insert images using the Drupal image styles.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

natedillon created an issue. See original summary.

Snater’s picture

Yes, you are right. I just rechecked that to be sure about the precise behaviour: In the D7 version, image styles could be activated on file fields which enabled images uploaded to such fields to be placed in the editor using image styles.

However, when not using the "Automatic" option (which was dropped in the D8 version) exclusively, non-image files could be placed in the editor with invalid image tag src attributes as the feature implementation was not complex enough. A silly thing is image detection (detecting allowed image formats) being hard-coded in the core image module with the D7 Insert module, basically, having to copy-paste it (causing conflicts with other modules); see D7 module insert.inc, line 30ff and D8 core's ImageWidget.php, line 121ff. These are the reasons why I was reluctant to copy the functionality over to the D8 version. Yet, I understand that it would be nice to have just one single field to handle any files. I guess that is the use case you are aiming at?

The thing is, as to core's architecture, it is not the best idea to mix image specifics into the file field, as using image specific logic on the common file field results in a dirty architectural state prone to conflicts. A more sensible solution would be to have a "combined" file/image field by extending core's image field and allowing to upload any file to it; Yet, that would result in having a non-standard (in terms of non-core) field and, due to the hard-coding issue, requires digging in the dirt as well.

Bottom line: I assume just hacking in the functionality of the D7 module would not be a big deal. Yet, the D7 functionality is prone to errors regarding usability and conflicts with other modules, which is why I dropped the functionality by intention and I am not sure it should be part of the Insert module—I might very well be wrong on my assumptions, though, and I am happy to discuss the feature.

(Without having tried, you might be able to easily hack your copy of the Insert module to be able to apply the "Insert Image" widget to a common file field by adding * "file" below * "image" in InsertImageWidget.php, line 21, and clearing cache afterwards.)

natedillon’s picture

That makes sense. I think for now I will just have to separate my images into an image-specific field and insert from there, and then I will keep all other files in a file upload field.

This week I have been digging into some of the new Drupal 8 media features for the first time, and it seems a bit confusing at the moment. They are adding a lot of media library type things, but it looks like the majority of that won't land until the fall. In 8.5, it looks like the media module is functional, but there didn't seem to be any great ways to get the media into the content. I'm not sure where this Insert module fits into all of that, but it seems like it could be beneficial until they build the media integration into the WYSIWYG.

natedillon’s picture

Assigned: natedillon » Unassigned
Snater’s picture

OK, so I will just leave it like that for now and leave the ticket open for a little while—maybe someone else has additional input on that. As far as I know, Entity Embed maintained by the Drupal Media Team is supposed to handle placing objects like images into the editor/body. That is the most prominent alternative to Insert. A major difference, however, is that Entity Embed creates invalid HTML using <drupal-entity data-*> tags. So, having started using Entity Embed, you are bound to that, which might be just ok depending on the use case. While not as tightly integrated, the Insert module creates valid HTML only and disabling Insert at some point in the future does not break any content.

Snater’s picture

Version: 8.x-1.0 » 8.x-2.x-dev
Assigned: Unassigned » Snater
Status: Active » Needs review
FileSize
37.2 KB

Some new developments on this: As of Drupal 8.5, image detection is not hard-coded anymore. Now, it is possible to smoothly combine file and image functionality of the Insert module. Insert would no more rely on the field type, but rather on the actual type of the uploaded file, to determine whether the file may be placed using image styles / an <img> tag.

With the attached change set combining both Insert module aspects, it is possible to insert images uploaded to generic file fields with the image styles activated on the field widget. (Image styles may be activated on file field widgets, similar to the module's Drupal 7 version.) Of course, this functionality has the limitation, resulting from the nature of the generic file field, that there is no preview image when uploading an image to a generic file field.

I am not yet perfectly sure if combining the functionality is a good idea, since the usability of configuring the widget is decreased to some extend, which is why I just uploaded the patch set to this issue ticket for now. If anybody wants to try it out and leave her/his opinion, very welcome. Else, I will make up my mind on my own whether this will be part of the 8.x-2.x version.

  • Snater committed 7ffa0e2 on 8.x-2.x
    Issue #2945191: Allow image insert for the file field
    
Snater’s picture

While also combining file and image Insert capability, the change submitted introduces a module configuration option to enable image insert functionality on file fields in order to navigate around probable usability pitfalls. Enabling the option will allow choosing image styles when inserting on file fields. But in the form the Insert functionality is attached to, image styles will only be selectable for actual images to avoid trying to insert non-image files with image styles.
This change makes Insert require Drupal core 8.5

  • Snater committed 7277591 on 8.x-2.x
    Issue #2945191: Ensure image styles are not available when inserting...
  • Snater committed eb02d1b on 8.x-2.x
    Issue #2945191: Populate alt attribute with description field when...
Snater’s picture

Status: Needs review » Fixed
Parent issue: » #2981038: Release 8.x-2.0
Related issues: +#2981037: Update documentation

Tested the feature once again. Works as expected.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.