Hello,
I'm using media with ckeditor for inserting images inside the body field of a content type. Everything seems to work fine, I'm able to insert the image, see it in the body field (node edit/add form) and save the content correctly. Then I can see the content with the image inserted in the body field.
The issue comes when editing the content:
1. If I do it with a user that have access to the "Text format" selectlist of the body field, there is no problem at all.
2. If I do it with a user that have no access to this selectlist the problem arises.
Could this come from this piece of code?:
<?php
/**
* Builds a map of media tags in the element.
*
* Builds a map of the media tags in an element that are being rendered to their
* rendered HTML. The map is stored in JS, so we can transform them when the
* editor is being displayed.
*/
function media_wysiwyg_pre_render_text_format($element) {
// filter_process_format() copies properties to the expanded 'value' child
// element.
if (!isset($element['format'])) {
return $element;
}
$field = &$element['value'];
$settings = array(
'field' => $field['#id'],
);
$tagmap = _media_wysiwyg_generate_tagMap($field['#value']);
if (isset($tagmap)) {
drupal_add_js(array('tagmap' => $tagmap), 'setting');
}
return $element;
}
?>
This function looks like it will run after some others that could change the access to the format filter selector, so the $element['format'] value might not be set at this point even if the user has access to the format filter itself.
Maybe checking user permissions for the current element format could solve the issue (patch attached).
This patch could also solve:
- Uncaught TypeError: Cannot read property 'tagName' of undefined
- When errors on form validation, the media "tokens" for the inserted image are removed
I'm not pretty sure about the code and don't know what side effects this patch could lead to, but if you guys could take a look it will be great.
Comments
Comment #1
tuwebo commentedComment #2
tuwebo commentedClarified some doc.
Comment #3
tuwebo commentedAdded a check for module_exists('filter') before using one of its functions.
Comment #6
kallehauge commentedI have the same problem. The problem occurs on textareas with only one filter available. So when the "Select Textformat" dropdown doesn't exist we completely skip the process of creating the tagmap for some reason?
I can't really figure out what the problem would be by having tagmaps on filters without the dropdown? I tried to do a "blame" to find the origin of the code, but it was a dead end.
Comment #7
kallehauge commentedWups, wrong naming of the file.
Comment #8
runephilosof commentedRebased the patch
Comment #9
chris matthews commentedClosing 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