Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with 'filebrowser' module #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions lib/features/nems_core/nems_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ function _nems_core_filefield_source_reference_get_files($filename, $instance =
*/
function nems_core_menu() {
$items['node/%node/%'] = array(
'page callback' => 'nems_core_wysiwyg_view_file',
'page arguments' => array(2),
'access arguments' => array('use media wysiwyg'),
'page callback' => '_nems_core_view_subnode',
'page arguments' => array(1, 2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);

Expand Down Expand Up @@ -343,28 +343,32 @@ function nems_core_admin_menu_output_build(&$content) {
}

/**
* Callback: serves images requested by the new file token.
* Callback: serves child node requested by the new token.
*
* @param stdClass $node
* Target node.
* @param string $filetoken
* File token passed through url.
* Node token passed through url.
*/
function nems_core_wysiwyg_view_file($filetoken) {
$fid = str_replace(array('[file:', ':url]'), '', $filetoken);
$fid = intval($fid);
$path = FALSE;

if (!empty($fid)) {
$file = file_load($fid);

if (!empty($file)) {
$path = file_create_url($file->uri);
function _nems_core_view_subnode($node, $filetoken) {
if (!empty($node->type)) {
switch ($node->type) {
case 'file':
if (!empty($node->uri)) {
$path = file_create_url($node->uri);
drupal_goto($path);
}
else {
drupal_not_found();
}
break;
default:
// Native workflow (used in filebrowser).
return node_show($node);
}
}

if (!empty($path)) {
drupal_goto($path);
}
else {
watchdog('nems_core', 'hook_menu with params ($node : %node, \n $filetoken : %filetoken', array('%node' => $node, '%filetoken' => $filetoken), WATCHDOG_NOTICE);
drupal_not_found();
}
}
Expand Down