Commit 424a359d authored by JacobSingh's avatar JacobSingh

#975496 by Gábor Hojtsy: css/js API change

parent 9cc8d966
......@@ -27,7 +27,7 @@ function media_wysiwyg_include_directory($type) {
*/
function media_filter($text) {
$text = ' ' . $text . ' ';
$text = preg_replace_callback("/\[\[.*?]]/s",'_media_markup', $text);
$text = preg_replace_callback("/\[\[.*?]]/s",'media_token_to_markup', $text);
return $text;
}
......@@ -112,6 +112,7 @@ function _media_url_curry($func, $arity) {
");
}
/**
* Replace callback to convert tag into markup
* @param string $match
......@@ -121,7 +122,7 @@ function _media_url_curry($func, $arity) {
* @return
* Return the replaced markup
*/
function _media_markup($match, $wysiwyg = FALSE) {
function media_token_to_markup($match, $wysiwyg = FALSE) {
$match = str_replace("[[","",$match);
$match = str_replace("]]","",$match);
$tag = $match[0];
......@@ -130,7 +131,7 @@ function _media_markup($match, $wysiwyg = FALSE) {
if (!is_string($tag)) {
throw new Exception('Unable to find matching tag');
}
$media = drupal_json_decode($tag);
if (!isset($media['fid'])) {
......@@ -207,7 +208,7 @@ function media_pre_render_text_format($element) {
*
* @see
* media_process_form
* _media_markup
* media_token_to_markup
*/
function _media_generate_tagMap($text) {
// Making $tagmap static as this function is called many times and
......@@ -226,7 +227,7 @@ function _media_generate_tagMap($text) {
if(empty($tagmap[$match[0]])) {
// @TODO: Total HACK, but better than nothing.
// We should find a better way of cleaning this up.
if ($markup_for_media = _media_markup($match, TRUE)) {
if ($markup_for_media = media_token_to_markup($match, TRUE)) {
$tagmap[$match[0]] = $markup_for_media;
} else {
$tagmap[$match[0]] = '<div><img src="/broken.jpg" height="50px" width="100px"/></div>';
......
......@@ -14,6 +14,9 @@ files[] = MediaReadOnlyStreamWrapper.inc
; Tests
files[] = test/media.types.test
files[] = test/media.entity.test
files[] = test/media.filter.test
dependencies[] = file
dependencies[] = image
dependencies[] = file_styles
testing_api = 2.x
......@@ -442,7 +442,7 @@ function media_media_operations() {
'redirect' => 'media/%fids/multiedit'
),
);
if (!module_exists('multiform')) {
// If the multiform module is not installed, do not show this option.
unset($operations['edit']);
......@@ -452,7 +452,7 @@ function media_media_operations() {
/**
* Implementation of hook_forms()
*/
*/
function media_forms($form_id, $args) {
$forms = array();
// To support the multiedit form, each form has to have a unique ID.
......@@ -491,7 +491,7 @@ function media_load($fid) {
*
* @return array
* An array of corresponding media entities.
*/
*/
function media_multi_load($fids) {
$fids = explode(" ", $fids);
if ($files = media_load_multiple($fids)) {
......@@ -665,9 +665,9 @@ function media_library() {
$libraries['media_base'] = array(
'title' => 'Media base',
'js' => array(
$path . '/javascript/media.core.js' => array('weight' => JS_LIBRARY - 5),
$path . '/javascript/util/json2.js' => array('weight' => JS_LIBRARY),
$path . '/javascript/util/ba-debug.min.js' => array('weight' => JS_LIBRARY),
$path . '/javascript/media.core.js' => array('group' => JS_LIBRARY, 'weight' => - 5),
$path . '/javascript/util/json2.js' => array('group' => JS_LIBRARY),
$path . '/javascript/util/ba-debug.min.js' => array('group' => JS_LIBRARY),
),
'css' => array(
$path . '/css/media.css',
......@@ -681,7 +681,7 @@ function media_library() {
$libraries['media_browser'] = array(
'title' => 'Media Browser popup libraries',
'js' => array(
$path . '/javascript/media.popups.js' => array('weight' => JS_DEFAULT),
$path . '/javascript/media.popups.js' => array('group' => JS_DEFAULT),
),
'dependencies' => array(
array('media', 'media_base'),
......@@ -697,10 +697,10 @@ function media_library() {
$libraries['media_browser_page'] = array(
'title' => 'Media browser',
'js' => array(
$path . '/javascript/media-browser.js' => array('weight' => JS_DEFAULT),
$path . '/javascript/media-browser.js' => array('group' => JS_DEFAULT),
),
'css' => array(
$path . '/css/media.browser.css' => array('weight' => CSS_DEFAULT),
$path . '/css/media.browser.css' => array('group' => CSS_DEFAULT),
),
'dependencies' => array(
array('media', 'media_base'),
......@@ -1006,10 +1006,10 @@ function media_element_process(&$element, &$form_state, $form) {
'type' => 'setting',
'data' => $setting,
);
// hmm... Might need to think about this.
// All settings would likely apply to all media in a multi-value, but what about passing the existing fid?
module_load_include('inc', 'media', 'media.browser');
media_include_browser_js();
......@@ -1119,6 +1119,6 @@ function media_file_validate_types(stdClass $file, $types) {
if (!in_array(media_get_type($file), $types)) {
$errors[] = t('Only the following types of files are allowed to be uploaded: %types-allowed', array('%types-allowed' => implode(', ', $types)));
}
return $errors;
}
......@@ -24,25 +24,6 @@ class MediaEntityTest extends DrupalWebTestCase {
// Nice, TDD FTW. #totalsarcasm
variable_set('simpletest_verbose', TRUE);
}
function createMedia($filename = NULL) {
if (!$filename) {
$filename = uniqid() . '.jpg';
}
//file_save_data()
$values = array(
'type' => 'image',
'uid' => 1,
'filename' => $filename,
'uri' => 'temporary://' . $filename,
'filemime' => 'image/jpeg',
'filesize' => 12345,
'status' => 1,
'timestamp'=> time(),
);
return file_save((object)$values);
}
/**
* Test the ability to create and query media items.
......@@ -82,4 +63,4 @@ class MediaEntityTest extends DrupalWebTestCase {
}
}
?>
\ No newline at end of file
?>
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