I am trying to add a custom Alignment field to media inserts. I added the field with a hook_form_alter(), and the field appeared. I was able to insert the media, and everything saved in the database, but the image did not get the appropriate attribute in the WYSIWYG. When I saved the node and viewed it, it had the attribute. It also had the attribute in the WYSIWYG when I edited the node.

The culprit turned out to be in addImageAttributes in wysiwyg-media.js where addImageAttributes is processing the additional object. The code from line 84 is:

for (k in additional) {
  if (additional.hasOwnProperty(k)) {
    if (k === 'attr') {
      imgElement.attr(k, additional[k]);
    }
  }
}

The if (k === 'attr') statement doesn't make sense because k will never === 'attr'. I got rid of that if statement, and it worked as expected:

for (k in additional) {
  if (additional.hasOwnProperty(k)) {
    imgElement.attr(k, additional[k]);
  }
}

Am I overlooking something? If not, I would be happy to create a patch.

Comments

jlyon’s picture

Issue summary: View changes

fixed code

mpgeek’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)
mpgeek’s picture

Status: Postponed (maintainer needs more info) » Active
mpgeek’s picture

Issue summary: View changes

fixed explanation

Chris Matthews’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Component: WYSIWYG integration » Code
Issue summary: View changes
Status: Active » Closed (outdated)

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