Comments

ParisLiakos’s picture

correct tag

arthurf’s picture

StatusFileSize
new1.8 KB

Here's a first pass at this. I think it's fine but we might may want to consider a css declaration on .media-element-container { display: inline; }

This patch doesn't cover sending data back to the WYSIWYG. I think it would be good to display field data in the WYSIWYG but that's beyond the scope of this issue I think.

arthurf’s picture

Status: Active » Needs review
ParisLiakos’s picture

I think it would be good to display field data in the WYSIWYG but that's beyond the scope of this issue I think.

i am confused..this already works? see http://drupal.org/node/1421786

arthurf’s picture

Actually I mean rendered in side of the WYSIWYG editor itself #1321786: Permission not working doesn't render fields inside along with the file- it just sends the image itself. I created #1888468: Render file fields inside the WYSIWYG editor to address this issue.

ParisLiakos’s picture

the problem here: when we apply a div, we actually output invalid html cause most editros wrap everything in <p>

<p><div>Something</div></p>

Is invalid html..sigh this is going to be a pita

dalin’s picture

Anyone coming to this issue from the borked #1169192: Add classes to images floated left or right that is looking for a way to add classes based on floats, the following is the easy way that doesn't deal with the divs-in-p-tags issue.

/**
 * Implements hook_media_token_to_markup_alter().
 */
function MYMODULE_media_media_token_to_markup_alter(&$element, $tag_info, $settings) {
  if (isset($element['content']['file']['#file'])) {
    if ($direction = _MYMODULE_media_has_float($element['content']['file']['#file']->override['attributes']['style'])) {
      $element['content']['file']['#file']->override['attributes']['class'][] = "media-image-$direction";
    }
    if ($direction = _MYMODULE_media_has_float($element['content']['file']['#attributes']['style'])) {
      $element['content']['file']['#attributes']['class'][] = "media-image-$direction";
    }
  }
}

/**
 * Does the given string contain a CSS rule to float:right or float:left?
 *
 * @param string $string
 *
 * @return boolean
 */
function _MYMODULE_media_has_float($string) {
  foreach (array('right', 'left') as $direction) {
    if (preg_match("!float\s*:\s*$direction!", $string)) {
      return $direction;
    }
  }
}
kirkofalltrades’s picture

dalin,

I'm very interested in using your module, but it doesn't appear to be working for me. I created the custom module, changed the function names to match in the .module file. I am using Media 7.x-2.0-unstable7. Do I need to be using the dev?

Thanks!

dippers’s picture

The fix in #8 has too many media in the function name, it should be MYMODULE_media_token_to_markup_alter.

The fix will not work with the media crop module as that ignores element attributes and uses the tag_info attributes instead.

ellen.davis’s picture

Looks like the wysiwyg stuff was moved into sub-modules at some point. After I upgraded to 7.x-2.0-alpha3+40-dev I found I needed to use this function instead.

function MYMODULE_media_wysiwyg_token_to_markup_alter(&$element, $tag_info, $settings) {
dddbbb’s picture

Seems like there's some overlap between this issue and https://drupal.org/node/2018075 - the latter is more up to date in that it works with the recent move to a Media WYSIWYG sub module. Neither of these issues are 100% solved but it would be great try to focus efforts on one issue if possible.

I've resisted marking as duplicate in case I've missed the point - can someone confirm if I'm on the right track here?

osopolar’s picture

Edit: sorry, wrong issue.

chris matthews’s picture

Status: Needs review » Closed (outdated)
Issue tags: -Needs issue summary update

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team