Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As a content editor, I attach a file to a filefield using the media widget and then insert a link to that file directly into a WYSIWYG editor.
Comment | File | Size | Author |
---|---|---|---|
#50 | add_insert_button_to-2451959-50.patch | 5.91 KB | brockfanning |
|
Comments
Comment #1
grasmash CreditAttribution: grasmash at Acquia for U.S. Department of Justice commentedThis patch adds a new 'Insert' button to the Media widget. This patch simply extends the Ckeditor integration. I have not tested it on plain text fields.
Comment #2
grasmash CreditAttribution: grasmash at Acquia for U.S. Department of Justice commentedUpdating patch. Ckeditor was throwing undefined error in some cases.
Comment #3
Devin Carlson CreditAttribution: Devin Carlson commentedThis is better handled by modules such as Insert, Insert Field and Advanced Entity Tokens.
Comment #4
grasmash CreditAttribution: grasmash at Acquia for U.S. Department of Justice commented@Devin This patch provides functionality that isn't provided by your solutions:
I'll look into AET but I believe that it has a less intuitive UI.
Comment #5
grasmash CreditAttribution: grasmash at Acquia for U.S. Department of Justice commentedYes, the AET module doesn't actually provides a UI with an 'Insert' button. Instead, it require that the user has an advanced understanding of entities, fields, and field deltas.
Given that I've submitted a patch, and that it provide functionality not available elsewhere, is there still a good rationale for leaving this feature out of Media?
Comment #6
dehacker CreditAttribution: dehacker commentedSwitched from 'media multiselect' widget to 'media browser' widget for file field. Insert module is installed but does not display Insert button in Media 7.2-alpha3.
Applied #2 patch and still do not see the Insert button using Attachments with WYSIWYG and CKeditor 4.4.7
Disabled manualcrop and the Insert button re-appeared on Attachments. Re-enable manualcrop and the Insert button remains.
Comment #7
brockfanning CreditAttribution: brockfanning commentedIn the latest dev version of Media, media_ckeditor has been split out into a separate project, so here is a reroll and slight modification of #2 that can be applied to media_ckeditor instead of media. The modification is a minor fix to prevent the hijacking of the normal Ckeditor toolbar button after the new insert buttons have been clicked. (Interdiff attached too.)
To be clear, if you use an older version of the Media module, from before media_ckeditor was split into a separate project, you would still need to use #2.
Comment #8
brockfanning CreditAttribution: brockfanning commentedComment #9
brockfanning CreditAttribution: brockfanning commentedA slight change to move the Insert button just before "Remove".
Comment #10
brockfanning CreditAttribution: brockfanning commentedAnother tweak to remove the href of "#", which can be problematic.
Comment #11
brockfanning CreditAttribution: brockfanning commentedYet another tweak, to fix a logic issue: If the user has a media item selected in the WYSIWYG and then click an "Insert" button, the popup reflects the selected (in the WYSIWYG) file, instead of the file associated with that "Insert" button. This update fixes that by re-arranging some logic.
Comment #12
brockfanning CreditAttribution: brockfanning commentedWhoops, code from another patch snuck in there. Trying again.
Comment #13
brockfanning CreditAttribution: brockfanning commentedThis is a version for anyone who also uses #2710841-8: The toolbar button does not open/edit selected media in latest CKEditor.
Comment #14
brockfanning CreditAttribution: brockfanning commentedThat didn't work. Once again, this is a version for anyone who also uses #2710841-8: The toolbar button does not open/edit selected media in latest CKEditor.
Comment #15
siramsay CreditAttribution: siramsay as a volunteer commentedTested Patch #12 and works. Thanks
Comment #16
brockfanning CreditAttribution: brockfanning commentedA slight tweak to deal with an edge case involving Ctool modals. This was happening:
So a simple fix is to do a safety check. I've wrapped the whole thing in:
Comment #17
brockfanning CreditAttribution: brockfanning commentedMessed up the alternate version, trying again.
Comment #18
brockfanning CreditAttribution: brockfanning commented#16 was broken because it relied on the Ckeditor instance to be instantiated before the code runs, which can't be assumed. Will have to accept the behavior described in #16 as an unfortunate edge case for now, and keep working on a better solution. Please disregard #16 and #17.
Comment #19
brockfanning CreditAttribution: brockfanning commentedHere is a re-roll and revamp of this functionality. With the new patch, this Insert button is configurable per file field instance. This should hopefully make this safer to use, since it doesn't change anything by itself. The insert button will only appear if you turn it on for a particular field instance. The option will appear as a checkbox in the field instance configuration, but only if the field widget is the Media browser.
I'll be testing this out. The only thing I'm not totally sure about is the changing of the weight of the library.js file from -20 to 20. That seems to be needed in order to have library.js fire after CKEditor is loaded. But I'll be keeping an eye on that for any issues.
Comment #20
brockfanning CreditAttribution: brockfanning commentedI need to test this alongside #2731335: Fully rendered file in WYSIWYG, including overridden fields, so here is a version that includes that patch. Please disregard this one and review #19.
Comment #21
siramsay CreditAttribution: siramsay as a volunteer commentedI have tried this and it doesn't work with my setup. (patch 19)
I get "Show button for inserting files into WYSIWYG editor" on the manage field page for a Media Browser field type but no insert button on a node edit page.
I haven't checked in to the code yet but is there something else I should know/do?
Comment #22
brockfanning CreditAttribution: brockfanning commented@size, can you check the browser console to see if any javascript errors are happening on the node edit page?
Comment #23
siramsay CreditAttribution: siramsay as a volunteer commented@brockfanning
I will try and investigate further as time allows but it seem that the js/plugins/media/library.js isn't even loading, I have tried changing it to other weights but still no joy, it just doesn't load.
using un-patched .module with patch 12, all is fine still.
Comment #24
joseph.olstad@size , which version of jQuery are you using? which version of jquery_update?
@brockfanning, which version of jQuery are you using?
jquery_update allows us to specify which version of jQuery is used by which theme, note that the theme used during admin tasks is not always the same as the theme used for displaying your content to the public.
Comment #25
brockfanning CreditAttribution: brockfanning commentedThe site where I'm running this patch uses jQuery 1.7.
@size: Just to make sure, does your node type have a long text field that defaults to use a text format associated with a CKEditor profile that has "Plugin for embedding files using Media CKEditor" checked?
Comment #26
siramsay CreditAttribution: siramsay as a volunteer commentedI have tried all options available for admin JQuery and have 1.7 as default, even though that shouldn't effect admin Jquery when it is different.
I have tried Bartik but generally have Seven as admin theme.
Something is stopping the load of the library.js on page load as you mention.
@brockfanning, yes I have "Plugin for embedding files using Media CKEditor" checked on all my CKEditor profiles. I am using the default body field / widget type: text area with a summary.
Comment #27
brockfanning CreditAttribution: brockfanning commented@size: I'm going to investigate further, thanks for the feedback. First though a quick re-roll since it doesn't apply anymore.
Comment #28
brockfanning CreditAttribution: brockfanning commentedOne problem is that it only worked for multi-value file fields, and did not work for single-value file fields. Here's a fix for that problem. @size: Do you think that could have been the issue?
Comment #29
siramsay CreditAttribution: siramsay as a volunteer commentedthanks @brockfanning
appreciate your work on this, I will also try and find sometime in the next week to see what I can come up with / apply your re-rolled patches. It is a nice feature and having it configurable per field is definitely the way to go, but for now I can live with #12 patch.
regarding file fields, I am using image fields with media browser widget, only using/wanting it on multi-valued (unlimited) fields.
as said will test re-rolled patches and get back to you.
Comment #30
siramsay CreditAttribution: siramsay as a volunteer commentedtested #28 and works with image field type (multi-value) with media widget.
insert toggle on configuration works as expected
thanks @brockfanning
Comment #31
joseph.olstad@brockfanning , do you want this committed and then tag a new release with this? I haven't yet tested this but if you say its good, lets put it in.
Comment #32
brockfanning CreditAttribution: brockfanning commentedAs far as I know this is a pretty harmless addition, because nothing should really change until the site builder makes an intentional configuration change; and it's working for me. That said, I'm not in a huge hurry to get this feature committed, since I'm happy to keep using a patch. If you'd prefer to wait and push for a 2.0 release before adding new features, that's fine with me.
Comment #33
joseph.olstadafter applying this patch, my linkit plugin stopped working, the dialog popup failed to load.
Backing off this patch restored my linkit functionality for an imce inserted image that uses the image plugin.
Comment #34
brockfanning CreditAttribution: brockfanning commentedThe only thing I can think of that might cause that is the changing of the javascript's weight, and now that I'm testing it again on a vanilla site, it doesn't seem like it needs to change. I'm hopeful that I was just mistaken when I thought that needed to be done. Here's another version with the weight changed back to normal. I'll test this on a client site tomorrow.Don't use this patch...
Comment #36
brockfanning CreditAttribution: brockfanning commentedYeah, it seems to work fine without changing the javascript weight. @size and @joseph.oldstad do you mind re-testing with #34?
Comment #38
siramsay CreditAttribution: siramsay as a volunteer commentedI still need weight set at 20, but with weight set at -20 the library.js is still loading but no insert button is attached. I haven't tested anything past that.
I don't have media_oembed as per the recipe at [#2843391] but other than that I think my set up is almost the same.
Comment #39
brockfanning CreditAttribution: brockfanning commentedAh, you're right @size, I hadn't tried testing with existing content. Ok, I'll hide #34, and #28 is still the best patch for now.
@joseph.oldstad: We need to figure out what's going wrong in your setup. I use Linkit, but not IMCE. I haven't noticed any issues with Linkit with this patch. Can you list the steps you're taking to get to the failure, so I can try and recreate it?
Comment #40
joseph.olstad@brockfanning , I'm using a few other ckeditor plugins like pastefromexcel and one or two others, plus imce , plus the image plugin (works with imce) and of course linkit.
I'll try to test this out again in the next few days possibly and see if there's some more debug info I can provide.
Comment #41
brockfanning CreditAttribution: brockfanning commentedComment #42
joseph.olstadI reviewed this, it didn't seem to harm anything, however I didn't yet actually test the insert button.
Comment #43
joseph.olstadUpon further regression testing of this patch it was found to break linkit integration.
When this patch applies, the linkit dialog fails to open fully, it opens with no items in it and locks up.
So I back off this patch, and linkit functionality is restored. So same issue as reported in #33
Comment #44
brockfanning CreditAttribution: brockfanning commented@joseph.olstad: Are there any javascript errors or any clues as to what might be going on? I am having trouble recreating that. I'm testing this recipe and Linkit seems to be unaffected:
Comment #45
joseph.olstadI'm using ckeditor 4.6.2
perhaps thats the difference.
I'll try to run some more tests see if there's some javascript error.
Comment #46
joseph.olstadAlso, we're using jQuery 1.4
Comment #47
brockfanning CreditAttribution: brockfanning commentedI forgot to add the entity module to the recipe above, FYI. It's there now.
I tried going up to CKEditor 4.6.2, and I'm still not getting problems with Linkit. I'm testing on standard Drupal 7 so I'm also using jQuery 1.4.
Comment #48
brockfanning CreditAttribution: brockfanning commentedThis is a version only for use with a totally unrelated patch, #2731335-33: Fully rendered file in WYSIWYG, including overridden fields. The patch to test is still #28 above.
Comment #49
joseph.olstadjQuery 1.4
TypeError:
Comment #50
brockfanning CreditAttribution: brockfanning commentedDoh, I didn't even think to test this without a Media widget being present. Makes sense, good catch! Here is another version that should hopefully fix that, and removes some unnecessary "typeof" operators. (Along with an interdiff, and an update to a temporary patch for use with an unrelated issue.)
Comment #51
brockfanning CreditAttribution: brockfanning commentedComment #52
junaidpvWe still require the patch to use with 2731335-33. It didn't apply with latest dev. Here is the rerolled one.The other patche applies without problem, so it is same as #50 above.Comment #53
junaidpvSorry that my above comment #52 is wrong. Both patches from #50 still applies.
Comment #55
joseph.olstadbeen sitting here long enough, committed patch 50 as-is.
Thanks to @brockfanning once again!