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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joseph.olstad created an issue. See original summary.

joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Note: there is a manual workaround for this using some small bit of custom code as documented by @brockfanning. see this comment:

rooby’s picture

It 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.

brockfanning’s picture

Project: Media CKEditor » D7 Media
Status: Needs work » Needs review
FileSize
2.41 KB

Edit: 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:

media-wysiwyg-right|Right
media-wysiwyg-left|Left

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:

.media-wysiwyg-right: { float: right; margin-left: 20px; }
.media-wysiwyg-left: { float: left; margin-right: 20px; }

So some things to discuss:

  1. Does this work and is this useful?
  2. Should we include pre-written CSS that assumes certain classes, like the example code above? If so, should that included CSS be optional?
  3. Is there anything we can do to make the configuration easier, or is instructions in a recipe the best we can do?
brockfanning’s picture

It 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?

rooby’s picture

I 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.

brockfanning’s picture

It 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.

brockfanning’s picture

I should mention, this patch includes a new config option on the media browser config page - a checkbox for turning on the alignment functionality.

joseph.olstad’s picture

@brockfanning , sounds like exactly what the doctor ordered, I'm looking forward to testing your patch out soon.

brockfanning’s picture

Note to self for a tweak that should be made to this patch: use hook_page_build() instead of hook_init() to add the css.

joseph.olstad’s picture

hook_page_build like this?

 /**
 * Implements hook_page_build().
 */
function media_wysiwyg_page_build($page) {
  // We need to load some minor CSS if media alignment is enabled.
  if (variable_get('media_wysiwyg_alignment', FALSE)) {
    $path = drupal_get_path('module', 'media_wysiwyg');
    drupal_add_css($path . '/css/media_wysiwyg.theme.css');
  }
}


Status: Needs review » Needs work

The last submitted patch, 12: media-wysiwyg-align-2842391-12.patch, failed testing.

joseph.olstad’s picture

sorry patch 12 is no good, I forgot the css .

joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
107.17 KB

tested it out, it works.
align right

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.

joseph.olstad’s picture

NOTE: you have to enable the alignment functionality before it will show up.

joseph.olstad’s picture

I'd say we should enable it by default.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review

trigger testbot on patch 15, DO NOT use patch 12, its missing the css file.

joseph.olstad’s picture

Version: 7.x-2.0-rc1 » 7.x-2.0-rc3
Status: Needs review » Reviewed & tested by the community
joseph.olstad’s picture

We should make this option enabled by default

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review

Actually, 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.

brockfanning’s picture

I 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.

joseph.olstad’s picture

This 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.

joseph.olstad’s picture

@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.

brockfanning’s picture

I 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

brockfanning’s picture

About 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.

brockfanning’s picture

joseph.olstad’s picture

we could probably commit the patch soon and if necessary spin off #1 and #2 as a new issues for followup.

brockfanning’s picture

#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.

joseph.olstad’s picture

wow great stuff @brockfanning, I'll test it asap. my default config is media_ckeditor ... I'll have to fire up wysiwyg

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
17.38 KB
87.98 KB

patch 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'?.
missing media properties
Didn't matter if the patch was used or not.

text format profile settings

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.

brockfanning’s picture

Did the centering work OK for you? In #30 I tweaked it slightly because it was getting stretched to full width sometimes.

joseph.olstad’s picture

Yes the centering worked too, great work!

just made a followup ticket in media_ckeditor
#2848856: media_ckeditor module to support the CKEditor widget system

joseph.olstad’s picture

My 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?

brockfanning’s picture

For 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. :)

joseph.olstad’s picture

@brockfanning
ok fair enough, that answers the interop question.

So lets commit it ? release it in 7.x-2.0-rc4

joseph.olstad’s picture

patch #30 as-is

brockfanning’s picture

I 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?

joseph.olstad’s picture

@brockfanning , good suggestion.

How about we add this?

/**
 * Notify upgraders that there's optional media alignment functionality that needs to be enabled.
 */
function media_wysiwyg_update_7206() {
  $message = t('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.');
  drupal_set_message($message,'status',TRUE);
}

joseph.olstad’s picture

feel free to suggest a wording change or simplify the message if you like.

brockfanning’s picture

Personally 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.

joseph.olstad’s picture

ok I like your simplified message. Lets go with that.

joseph.olstad’s picture

Here's what a 'status' message will look like.
status message alignment upgrade

I'm thinking it should be changed to 'warning' , this will grab a bit more attention.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
8.08 KB
joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

still RTBC, just wanted to trigger the testbot

  • brockfanning authored 72fe72c on 7.x-2.x
    Issue #2842391 by brockfanning, joseph.olstad: better support for float...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

***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

rooby’s picture

This is awesome guys!

2.0 is getting excitingly close.

Status: Fixed » Closed (fixed)

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

joseph.olstad’s picture

Might soon use this design pattern to add some optional css styles for size , quarter, half, third, three-quarter, etc. so like

.third {
height: 33%;
width: 33%;
}

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.

heyyo’s picture

Hi 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.

joseph.olstad’s picture

try 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.