Commit 1f96f2fc authored by olstjos's avatar olstjos

Merge branch '7.x-3.x' into 7.x-2.x

parents 1c75fc8f 621c51e7
......@@ -557,10 +557,14 @@ function theme_media_widget_multiple($variables) {
);
}
$table = array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id));
drupal_alter('media_widget_multiple', $table, $element);
drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class);
$output = '';
$output = empty($rows) ? '' : theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id)));
$output = empty($rows) ? '' : theme('table', $table);
$output .= drupal_render_children($element);
return $output;
}
......
......@@ -87,8 +87,8 @@ function media_update_dependencies() {
'rules' => 7205,
);
// Those updates require {file_type} table created.
$dependencies['media'][7204] = array(
'file_entity' => 7201,
$dependencies['media'][7200] = array(
'file_entity' => 7207,
);
// Require {file_type}.mimetypes column before updating them.
$dependencies['media'][7208] = array(
......
......@@ -1230,9 +1230,9 @@ function media_set_browser_params() {
);
$params = array_intersect_key($params, array_flip($safe_options));
// Retrieve the security sensitive options from the cache.
// If the cache is present, use its values instead of the GET parameters.
if (!empty($params['options']) && is_string($params['options']) && $options = cache_get('media_options:' . $params['options'], 'cache_form')) {
$params = array_merge($options->data, $params);
$params = $options->data;
}
// Transform text 'true' and 'false' to actual booleans.
......
......@@ -33,6 +33,7 @@ function media_views_plugins() {
'help' => t('Display as a tab in the media browser.'),
'handler' => 'media_views_plugin_display_media_browser',
'theme' => 'views_view',
'theme path' => drupal_get_path('module', 'views') . '/theme',
'base' => $base,
'use ajax' => TRUE,
'use pager' => TRUE,
......
......@@ -5,7 +5,7 @@
* Functions related to the WYSIWYG editor and the media input filter.
*/
define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[.*?\]\]/s');
define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[.+?"type":"media".+?\]\]/s');
/**
* Filter callback for media markup filter.
......@@ -27,21 +27,70 @@ function media_wysiwyg_filter($text, $filter = NULL, $format = NULL, $langcode =
return $rendered_text;
}
/**
* Filter callback to configure media_filter_paragraph_fix filter.
*/
function _media_filter_paragraph_fix_settings($form, &$form_state, $filter, $format, $defaults) {
$filter->settings += $defaults;
$settings['replace'] = array(
'#type' => 'checkbox',
'#title' => t('Replace paragraph tags with DIV.media-p tags'),
'#default_value' => $filter->settings['replace'],
'#description' => t('Default behaviour is to strip out parent P tags of media elements rather than replacing these.'),
);
return $settings;
}
/**
* Filter callback to remove paragraph tags surrounding embedded media.
*/
function media_wysiwyg_filter_paragraph_fix($text) {
function media_wysiwyg_filter_paragraph_fix($text, $filter) {
$html_dom = filter_dom_load($text);
// Store Nodes to remove to avoid inferferring with the NodeList iteration.
$dom_nodes_to_remove = array();
foreach ($html_dom->getElementsByTagName('p') as $paragraph) {
if (preg_match(MEDIA_WYSIWYG_TOKEN_REGEX, $paragraph->nodeValue)) {
$sibling = $paragraph->firstChild;
do {
$next = $sibling->nextSibling;
$paragraph->parentNode->insertBefore($sibling, $paragraph);
} while ($sibling = $next);
$paragraph->parentNode->removeChild($paragraph);
if (empty($filter->settings['replace'])) {
$sibling = $paragraph->firstChild;
do {
$next = $sibling->nextSibling;
$paragraph->parentNode->insertBefore($sibling, $paragraph);
} while ($sibling = $next);
$dom_nodes_to_remove[] = $paragraph;
}
else {
// Clone the P node into a DIV node.
$div = $html_dom->createElement('div');
$sibling = $paragraph->firstChild;
do {
$next = $sibling->nextSibling;
$div->appendChild($sibling);
} while ($sibling = $next);
$classes = array('media-p');
if ($paragraph->hasAttributes()) {
foreach ($paragraph->attributes as $attr) {
$name = $attr->nodeName;
$value = $attr->nodeValue;
if (strtolower($name) == 'class') {
$classes[] = $value;
}
else {
// Supressing errors with ID attribute or duplicate properties.
@$div->setAttribute($name, $value);
}
}
}
$div->setAttribute('class', implode(' ', $classes));
$paragraph->parentNode->insertBefore($div, $paragraph);
$dom_nodes_to_remove[] = $paragraph;
}
}
}
foreach ($dom_nodes_to_remove as $paragraph) {
$paragraph->parentNode->removeChild($paragraph);
}
$text = filter_dom_serialize($html_dom);
return $text;
}
......
......@@ -175,7 +175,8 @@
Drupal.media.filter.ensure_tagmap();
// Locate and process all the media placeholders in the WYSIWYG content.
var contentElements = $('<div/>').html(content); // TODO: once baseline jQuery is 1.8+, switch to using $.parseHTML(content)
var contentElements = $('<div/>'); // TODO: once baseline jQuery is 1.8+, switch to using $.parseHTML(content)
contentElements.get(0).innerHTML = content;
var mediaElements = contentElements.find('.media-element');
if (mediaElements) {
$(mediaElements).each(function (i) {
......
......@@ -12,5 +12,6 @@ test_dependencies[] = wysiwyg
files[] = media_wysiwyg.test
files[] = tests/media_wysiwyg.file_usage.test
files[] = tests/media_wysiwyg.macro.test
files[] = tests/media_wysiwyg.paragraph_fix_filter.test
configure = admin/config/media/browser
......@@ -342,8 +342,12 @@ function media_wysiwyg_filter_info() {
$filters['media_filter_paragraph_fix'] = array(
'title' => t('Ensure that embedded Media tags are not contained in paragraphs'),
'description' => t('This filter will strip any paragraph tags surrounding embedded Media tags. This helps to avoid the chopped up markup that can result from unexpectedly closed paragraph tags. This filter should be positioned above (before) the "Convert Media tags to markup" filter.'),
'description' => t('This filter will fix any paragraph tags surrounding embedded Media tags. This helps to avoid the chopped up markup that can result from unexpectedly closed paragraph tags. This filter should be positioned above (before) the "Convert Media tags to markup" filter.'),
'process callback' => 'media_wysiwyg_filter_paragraph_fix',
'settings callback' => '_media_filter_paragraph_fix_settings',
'default settings' => array(
'replace' => 0,
),
'weight' => 1,
);
......
......@@ -58,9 +58,11 @@ abstract class MediaWYSIWYGTestHelper extends DrupalWebTestCase {
);
// Create the file usage markup.
$markup .= '<p>Intro paragraph</p>';
for ($i = 1; $i <= $count; $i++) {
$markup .= '<p>[[' . drupal_json_encode($data) . ']]</p>';
}
$markup .= '<p>Finish paragraph</p>';
return $markup;
}
......
<?php
/**
* @file
* Tests for ensuring filters are working properly.
*/
/**
* Defines media macro test cases.
*/
class MediaWYSIWYGParagraphFixFilterTest extends MediaWYSIWYGTestHelper {
/**
* Defines the regex to test for a media tag replacement.
*
* @var string
*/
protected $regexpMediaTag = '/<div [^>]*media\-element\-container[^>]*>/i';
/**
* Defines the regex to test for in the raw body field source.
*
* @var string
*/
protected $regexpPWrapped = '/<p[^>]*><div [^>]*media\-element\-container[^>]*>/i';
/**
* Defines the regex to test for the P replacement filter.
*
* @var string
*/
protected $regexpReplaced = '/<div class\="media\-p"><div/i';
/**
* Provide test information.
*/
public static function getInfo() {
return array(
'name' => t('Media WYSIWYG Paragraph Filter Test'),
'description' => t('Tests that this media filter is working.'),
'group' => t('Media WYSIWYG'),
'dependencies' => array('token'),
);
}
/**
* Set-up the system for testing without the filter enabled.
*/
public function setUp() {
parent::setUp('token');
// Create and log in a user.
$account = $this->drupalCreateUser(array(
'create article content',
'administer filters',
'use text format filtered_html',
));
$this->drupalLogin($account);
// Enable the media filter for full html.
$edit = array(
'filters[media_filter][status]' => TRUE,
'filters[filter_autop][status]' => FALSE,
'filters[filter_html][status]' => FALSE,
'filters[filter_htmlcorrector][status]' => FALSE,
);
$this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
}
/**
* Test image media overrides.
*/
public function testMediaFilterParagraphFixMultipleImages() {
$files = $this->drupalGetTestFiles('image');
$file = file_save($files[0]);
// Create a node to test with 3 images.
$nid = $this->createNode($file->fid);
$node = node_load($nid);
$node->body[LANGUAGE_NONE][0]['value'] = $this->generateJsonTokenMarkup($file->fid, 3);
node_save($node);
// Check without the filter enabled.
$html = $this->drupalGet('node/' . $nid);
$count = preg_match_all($this->regexpMediaTag, $html);
$this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
$count = preg_match_all($this->regexpPWrapped, $html);
$this->assertEqual($count, 3, t('Three media tags with original wrapping HTML present, found @count.', array('@count' => $count)));
$count = preg_match_all($this->regexpReplaced, $html);
$this->assertEqual($count, 0, t('No media tags with P replaced present, found @count.', array('@count' => $count)));
// Enable the default P fix filter.
$edit = array(
'filters[media_filter_paragraph_fix][status]' => TRUE,
);
$this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
$html = $this->drupalGet('node/' . $nid);
$count = preg_match_all($this->regexpMediaTag, $html);
$this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
$count = preg_match_all($this->regexpPWrapped, $html);
$this->assertEqual($count, 0, t('No media tags with original wrapping HTML present, found @count.', array('@count' => $count)));
$count = preg_match_all($this->regexpReplaced, $html);
$this->assertEqual($count, 0, t('No media tags with P replaced present, found @count.', array('@count' => $count)));
// Enable the replace P fix filter option.
$edit = array(
'filters[media_filter_paragraph_fix][settings][replace]' => TRUE,
);
$this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
$html = $this->drupalGet('node/' . $nid);
$count = preg_match_all($this->regexpMediaTag, $html);
$this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
$count = preg_match_all($this->regexpPWrapped, $html);
$this->assertEqual($count, 0, t('No media tags with original wrapping HTML present, found @count.', array('@count' => $count)));
$count = preg_match_all($this->regexpReplaced, $html);
$this->assertEqual($count, 3, t('Three media tags with P replaced present, found @count.', array('@count' => $count)));
}
/**
* Test image media overrides.
*/
public function testMediaFilterParagraphFixDefault() {
$files = $this->drupalGetTestFiles('image');
$file = file_save($files[0]);
// Create a node to test with.
$nid = $this->createNode($file->fid);
// Check without the filter enabled.
$this->drupalGet('node/' . $nid);
$this->assertPattern($this->regexpPWrapped, t('Nested media DIV tags within paragraphs without filter.'));
$this->assertNoPattern($this->regexpReplaced, t('No replacement DIV tag found without filter.'));
// Enable the default P fix filter.
$edit = array(
'filters[media_filter_paragraph_fix][status]' => TRUE,
);
$this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
// Retest the content to check nested paragraphs are removed.
$this->drupalGet('node/' . $nid);
$this->assertNoPattern($this->regexpPWrapped, t('Nested media DIV tags within paragraphs with filter defaults.'));
$this->assertNoPattern($this->regexpReplaced, t('No replacement DIV tag found with filter defaults.'));
// Enable replacement option.
$edit = array(
'filters[media_filter_paragraph_fix][settings][replace]' => TRUE,
);
$this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
// Test that the replace text was found.
$this->drupalGet('node/' . $nid);
$this->assertNoPattern($this->regexpPWrapped, t('No nested media DIV tags within paragraphs with filter P replacement.'));
$this->assertPattern($this->regexpReplaced, t('No replacement DIV tag found with filter P replacement.'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment