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.
to overflow text around media (images or whatever)
it was suggested by @brockfanning that we could:
- add integration with the field_formatter_css_class module
Lets create a recipe for this. and add it to the media documentation.
Alternatively you can forgo the widget system and stick to the 'wysiwyg' module with 'media' and 'media_wysiwyg' . Using image properties through the wysiwyg.
Lets create a recipe for this. and add it to the media documentation.
Comment | File | Size | Author |
---|---|---|---|
#45 | media-wysiwyg-align-2842391-45.patch | 8.08 KB | joseph.olstad |
| |||
#44 | status_new_functionality_align_left_right_centre.png | 5.75 KB | joseph.olstad |
#32 | wysiwyg_test_media_patch_alignment_CKeditor_profile.jpg | 87.98 KB | joseph.olstad |
#32 | wysiwyg_test_media_patch_alignment.jpg | 17.38 KB | joseph.olstad |
Comments
Comment #2
joseph.olstadComment #3
joseph.olstadNote: there is a manual workaround for this using some small bit of custom code as documented by @brockfanning. see this comment:
Comment #4
rooby CreditAttribution: rooby commentedIt would be great if floating left and right could be somehow available out of the box, instead of just a recipe, however that probably isn't something that needs to hold up a 2.0 release.
Comment #5
brockfanning CreditAttribution: brockfanning commentedEdit: Before investigating this approach - skip to #8. It might be better.
Here's a introductory patch to start thinking about this. I don't consider this a finished patch, but am just posting to spur discussion. This patch allows you to have a field on the field type that adds a CSS class to the rendered media.
In order for this to work, you'll need to do a few things:
A. Download and install the field_formatter_css_class module.
B. Add a field to your file type that will be used to control a CSS class. For example, you might add a List (text) field called "Media Alignment" with allowed options of:
Make sure that this new field is set to be "Overridden in WYSIWYG". If that is not an option, you probably need to check "List (text)" under "Override field types in WYSIWYG" on /admin/config/media/browser.
C. Go to "Manage Display" for the file type and change the Format for the new field to "CSS Class". Then click the settings icon to configure the formatter, and change "Target tag" to "Embedded media", and click "Update" and then "Save".
After this, that new field will control a CSS class on the rendered media. This, by itself, still won't do anything, unless there is CSS to react to this new class. Some example CSS might be:
So some things to discuss:
Comment #6
brockfanning CreditAttribution: brockfanning commentedIt actually looks like this integration is going to go into the field_formatter_css_class module: #2844254: Support for Media?
So this will work, but that leaves us with the question of how to make this out-of-the-box, or at least easier for the user. If we want to allow this without any custom code, we'll need to provide a mechanism for adding some pre-written CSS - like a checkbox on an admin page that says "Check this to enable styles for aligning media to the left/right of content. See here for more details: [link to a drupal.org page with the configuration steps]".
How does that sound?
Comment #7
rooby CreditAttribution: rooby commentedI haven't tried it out yet but it sounds like a good solution to me.
As for the pre-written CSS, is there any precedent for this kind of thing in media_wysiwyg?
Although it is something that would be great I'm not really sure where it belongs and I'm coming around to the idea of just giving instructions since there are a few moving parts.
If the user has to add their own float field with their own CSS classes then really they probably should also do their own CSS.
Comment #8
brockfanning CreditAttribution: brockfanning commentedIt occurred to me to take a step back and see if this could be done in a more hard-coded way, rather than relying on field_formatter_css_class. Here's a fairly simple patch that might do it. If we want to go in this direction, we should test this thoroughly, since it adds a new item in the token.
Comment #9
brockfanning CreditAttribution: brockfanning commentedI should mention, this patch includes a new config option on the media browser config page - a checkbox for turning on the alignment functionality.
Comment #10
joseph.olstad@brockfanning , sounds like exactly what the doctor ordered, I'm looking forward to testing your patch out soon.
Comment #11
brockfanning CreditAttribution: brockfanning commentedNote to self for a tweak that should be made to this patch: use hook_page_build() instead of hook_init() to add the css.
Comment #12
joseph.olstadhook_page_build like this?
Comment #14
joseph.olstadsorry patch 12 is no good, I forgot the css .
Comment #15
joseph.olstadComment #16
joseph.olstadtested it out, it works.
As for the rest, it might need some tweaks in the css to control the flow to the left or right. But yes its working, great work @brockfanning.
Comment #17
joseph.olstadNOTE: you have to enable the alignment functionality before it will show up.
Comment #18
joseph.olstadI'd say we should enable it by default.
Comment #19
joseph.olstadtrigger testbot on patch 15, DO NOT use patch 12, its missing the css file.
Comment #20
joseph.olstadComment #21
joseph.olstadWe should make this option enabled by default
Comment #22
joseph.olstadActually, to make this work out of the box we also have to make sure those new media-wysiwyg-media css classes gets included when rendering the page.
still a couple things to do , but it's almost there.
Comment #23
brockfanning CreditAttribution: brockfanning commentedI was thinking of using '#attached' to add the CSS, but that's close. I'll try to post a slight tweak when I have time.
I personally lean more towards having it disabled by default, at this point. Most sites using media_wysiwyg probably already have some arrangement set up for handle alignment. For example, the site I work on would not want this on, because we've already got a field controlling alignment. If we have this enabled by default, we'd have to include some release notes telling people they might need to turn it off.
Maybe a compromise would be to have it disabled by default but, but enable it manually in hook_install(), so that new sites would start with it on, but existing sites would not experience any change of behavior.
Comment #24
joseph.olstadThis patch forces the align css to load on every page , otherwise it wouldn't render the css.
TODO:
make the css align left and align right classes work inside the wysiwyg editor it'self.. Wasn't sure how to do this yet.
Comment #25
joseph.olstad@brockfanning , yes I agree with the compromise, make it enabled in install by default for new installs, otherwise disabled by default, sorry I didn't see your message before I put up the new patch.
Comment #26
brockfanning CreditAttribution: brockfanning commentedI haven't tested this but here are some tweaks:
* using #attached to add the CSS
* change the CSS file to a .base.css file, since I think that is more appropriate here
* let the CSS group be the default, since we do want to let themes override this
* prevent this behavior unless enabled, but enable it in hook_install
* remove the variable on uninstall
Comment #27
brockfanning CreditAttribution: brockfanning commentedAbout getting the alignment to work inside the WYSIWYG: I agree that would be awesome. I don't know for sure but I suspect that would need to be done in 2 places:
1: In this module, to support the WYSIWYG module.
2: In the media_ckeditor module to support the CKEditor widget system.
So I guess this patch isn't complete until we've done #1.
Comment #28
brockfanning CreditAttribution: brockfanning commentedComment #29
joseph.olstadwe could probably commit the patch soon and if necessary spin off #1 and #2 as a new issues for followup.
Comment #30
brockfanning CreditAttribution: brockfanning commented#2 definitely needs a separate issue because it would be done in a separate project. But #1 probably makes sense to do here, so here's a quick attempt, with a few more tweaks.
Comment #31
joseph.olstadwow great stuff @brockfanning, I'll test it asap. my default config is media_ckeditor ... I'll have to fire up wysiwyg
Comment #32
joseph.olstadpatch works as advertised.
Unrelated issue: In amidst my configuration change from media_ckeditor to wysiwyg I had a bit of a time with the media widget plugin losing the 'media properties' option on right click. It seems that the image plugin took over even though I had it 'disabled'?.
Didn't matter if the patch was used or not.
I'm not sure why my environment has problems with the media properties , I'll have to test on a vanilla environment.
However, your patch looks great, patch 30 I'd say is ready for commit.
Comment #33
brockfanning CreditAttribution: brockfanning commentedDid the centering work OK for you? In #30 I tweaked it slightly because it was getting stretched to full width sometimes.
Comment #34
joseph.olstadYes the centering worked too, great work!
just made a followup ticket in media_ckeditor
#2848856: media_ckeditor module to support the CKEditor widget system
Comment #35
joseph.olstadMy only concern with this new functionality is having it disabled by default.
There's probably few people that have custom configured alignments and if they do this will probably work side by side with those configurations.
@brockfanning have you tested this patch on your custom configured media implementation? How is the interop?
Comment #36
brockfanning CreditAttribution: brockfanning commentedFor me it's not a question of compatibility, it's a question of editor experience and content integrity. If I were using this patch and it were enabled by default, then my users would suddenly see 2 separate alignment inputs, which would cause some confusion and complaints - probably some people using the wrong one, and result in a content headache. If I were going to migrate over to this new system, that could be done maybe, but it would involve a very deliberate update script to catch all existing content.
So if this were enabled by default, I would definitely disable it as soon as I knew. And if it caught me by surprise I (and my users) would be annoyed. :)
Comment #37
joseph.olstad@brockfanning
ok fair enough, that answers the interop question.
So lets commit it ? release it in 7.x-2.0-rc4
Comment #38
joseph.olstadpatch #30 as-is
Comment #39
brockfanning CreditAttribution: brockfanning commentedI guess one option if you want people to be aware of it is to put in an update function that just gives the user a notice with drupal_set_message(). I believe that's a thing some modules do?
Comment #40
joseph.olstad@brockfanning , good suggestion.
How about we add this?
Comment #41
joseph.olstadfeel free to suggest a wording change or simplify the message if you like.
Comment #42
brockfanning CreditAttribution: brockfanning commentedPersonally I like a shorter less technical message, something like:
If you would like to be able to align your embedded media (left, right, or center), go to /admin/config/media/browser and check "Provide alignment option when embedding media", and save the settings.
Comment #43
joseph.olstadok I like your simplified message. Lets go with that.
Comment #44
joseph.olstadHere's what a 'status' message will look like.
I'm thinking it should be changed to 'warning' , this will grab a bit more attention.
Comment #45
joseph.olstadComment #46
joseph.olstadstill RTBC, just wanted to trigger the testbot
Comment #48
joseph.olstad***EDIT***
This will make it into media 7.x-2.0-rc4
, or perhaps 7.x-2.0 whichever comes first..
7.x-2.0-rc4 has been released
Comment #49
rooby CreditAttribution: rooby commentedThis is awesome guys!
2.0 is getting excitingly close.
Comment #51
joseph.olstadMight soon use this design pattern to add some optional css styles for size , quarter, half, third, three-quarter, etc. so like
this was something my clients asked for, although there are image styles already, something similar to what @brockfanning did here could be a helpful extra functionality should someone not want to use image styles or not want to be bothered with extra configuration.
Comment #52
heyyo CreditAttribution: heyyo commentedHi Guys,
I just followed the new media recipe for Drupal 7. https://www.drupal.org/node/2843391
It's working perfectly.
I'm just missing the image alignment inside the Wysiwyg editor itself, viewing the node works nicely.
The alignement with image2 plugin is working inside Wysiwyg but not the one available via media button I enabled the option "Provide alignment option when embedding media" in /admin/config/media/browser page.
Comment #53
joseph.olstadtry this patch
#2919974-15: Media_WYSIWYG css is not loading in CKeditor iFrame
help me review it, if it works for you please let me know asap.