Commit 95877166 authored by Kevin Paxman's avatar Kevin Paxman
Browse files

Add patch from...

Add patch from https://www.drupal.org/project/ckeditor_link/issues/1491750#comment-11810261 to support arguments on internal links.
parent 495b5e2c
......@@ -29,6 +29,12 @@ function ckeditor_link_settings_form() {
'#options' => drupal_map_assoc(array(10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100)),
'#default_value' => variable_get('ckeditor_link_limit', 10),
);
$form['general']['ckeditor_link_args_field'] = array(
'#type' => 'checkbox',
'#title' => t('Extra arguments field'),
'#description' => t('Add a field below the autocomplete for additional arguments, query parameters or hash fragment.'),
'#default_value' => variable_get('ckeditor_link_args_field', 0),
);
$types = ckeditor_link_get_types();
foreach ($types as $type) {
......
......@@ -98,7 +98,7 @@ function ckeditor_link_revert() {
if (function_exists($func)) {
$result = $func($path, $langcode);
if ($result !== NULL) {
$output = ($result !== FALSE) ? $result .' ('. ckeditor_link_path_prefix_language($path, $langcode) .')' : FALSE;
$output = ($result !== FALSE) ? $result .' ('. ckeditor_link_path_prefix_language(ckeditor_link_path_strip_args($path), $langcode) .')' : FALSE;
break;
}
}
......@@ -203,6 +203,9 @@ function ckeditor_link_text_format_post_render($content, $element) {
'msg_invalid_path' => t('Link must be a valid internal path.'),
'type_name' => ckeditor_link_get_link_type_name(),
'type_selected' => (bool) variable_get('ckeditor_link_type_selected', 1),
'args_field' => (bool) variable_get('ckeditor_link_args_field', 0),
'path_args_label' => t('Extra arguments, query or fragment'),
'msg_invalid_args' => t('Extra arguments, query or fragment is not valid.'),
)), 'setting');
}
}
......@@ -311,6 +314,21 @@ function ckeditor_link_path_prefix_language($path, $langcode) {
return $path;
}
function ckeditor_link_path_strip_args($path, $router_item = NULL) {
if (!$router_item) {
$router_item = menu_get_item($path);
}
// Trim supplied path to router item path length.
if (isset($router_item['path'])) {
$arg_count = count(explode('/', $router_item['path']));
$path = explode('/', $path);
return implode('/', array_slice($path, 0, $arg_count));
}
return $path;
}
function ckeditor_link_get_languages() {
static $languages;
......
......@@ -57,6 +57,7 @@ function ckeditor_link_ckeditor_link_i18n_menu_revert($path, &$langcode) {
if (!$router_item['access']) {
return FALSE;
}
$path = ckeditor_link_path_strip_args($path, $router_item);
$result = db_query('SELECT mlid, link_title, language FROM {menu_links} WHERE link_path = :link_path AND hidden = 0 ORDER BY customized DESC', array(':link_path' => $path));
$default_langcode = language_default('language');
$link_title = NULL;
......
......@@ -46,7 +46,8 @@ function ckeditor_link_ckeditor_link_i18n_taxonomy_autocomplete($string, $limit)
* Implementation of hook_ckeditor_link_TYPE_revert().
*/
function ckeditor_link_ckeditor_link_i18n_taxonomy_revert($path, &$langcode) {
if (!preg_match('`^taxonomy/term/(\d+)$`', $path, $matches)) {
// Allow extra args, query parameters and hash fragments.
if (!preg_match('`^taxonomy/term/(\d+)(/[\w_+,-]+)?(\?[\w &=+_,;-]+)?(#[\w_-]+)?$`', $path, $matches)) {
return;
}
......
......@@ -55,6 +55,7 @@ function ckeditor_link_ckeditor_link_menu_revert($path, &$langcode) {
if (!$router_item['access']) {
return FALSE;
}
$path = ckeditor_link_path_strip_args($path, $router_item);
$link_title = db_query("SELECT link_title FROM {menu_links} WHERE link_path = :link_path AND hidden = 0 ORDER BY customized DESC", array(':link_path' => $path))->fetchField();
return ($link_title) ? $link_title : NULL;
}
......
......@@ -36,7 +36,8 @@ function ckeditor_link_ckeditor_link_node_autocomplete($string, $limit) {
* Implementation of hook_ckeditor_link_TYPE_revert().
*/
function ckeditor_link_ckeditor_link_node_revert($path, &$langcode) {
if (!preg_match('`^node/(\d+)$`', $path, $matches)) {
// Allow extra args, query parameters and hash fragments.
if (!preg_match('`^node/(\d+)(/[\w/_+,-]+)?(\?[\w &=+_,;-]+)?(#[\w_-]+)?$`', $path, $matches)) {
return;
}
......@@ -59,11 +60,13 @@ function ckeditor_link_ckeditor_link_node_revert($path, &$langcode) {
* Implementation of hook_ckeditor_link_TYPE_url().
*/
function ckeditor_link_ckeditor_link_node_url($path, $langcode) {
if (!preg_match('`^node/(\d+)$`', $path, $matches)) {
// Allow extra args, query parameters and hash fragments.
if (!preg_match('`^node/(\d+)(/[\w/_+,-]+)?(\?[\w &=+_,;-]+)?(#[\w_-]+)?$`', $path, $matches)) {
return;
}
$nid = $matches[1];
$extra = isset($matches[2]) ? $matches[2] : '';
$languages = ckeditor_link_get_languages();
if ($languages) {
......@@ -73,7 +76,7 @@ function ckeditor_link_ckeditor_link_node_url($path, $langcode) {
}
}
return ckeditor_link_url("node/$nid", $langcode);
return ckeditor_link_url("node/$nid$extra", $langcode);
}
/**
......
......@@ -36,7 +36,8 @@ function ckeditor_link_ckeditor_link_taxonomy_autocomplete($string, $limit) {
*/
function ckeditor_link_ckeditor_link_taxonomy_revert($path, &$langcode) {
if (function_exists('ckeditor_link_ckeditor_link_i18n_taxonomy_revert')
|| !preg_match('`^taxonomy/term/(\d+)$`', $path, $matches)) {
// Allow extra args, query parameters and hash fragments.
|| !preg_match('`^taxonomy/term/(\d+)(/[\w/_+,-]+)?(\?[\w &=+_,;-]+)?(#[\w_-]+)?$`', $path, $matches)) {
return;
}
......@@ -54,11 +55,13 @@ function ckeditor_link_ckeditor_link_taxonomy_revert($path, &$langcode) {
* Implementation of hook_ckeditor_link_TYPE_url().
*/
function ckeditor_link_ckeditor_link_taxonomy_url($path, $langcode) {
if (!preg_match('`^taxonomy/term/(\d+)$`', $path, $matches)) {
// Allow extra args, query parameters and hash fragments.
if (!preg_match('`^taxonomy/term/(\d+)(/[\w/_+,-]+)?(\?[\w &=+_,;-]+)?(#[\w_-]+)?$`', $path, $matches)) {
return;
}
$tid = $matches[1];
$extra = isset($matches[2]) ? $matches[2] : '';
$languages = ckeditor_link_get_languages();
if ($languages) {
......@@ -68,7 +71,7 @@ function ckeditor_link_ckeditor_link_taxonomy_url($path, $langcode) {
}
}
return ckeditor_link_url("taxonomy/term/$tid", $langcode);
return ckeditor_link_url("taxonomy/term/$tid$extra", $langcode);
}
/**
......
......@@ -60,8 +60,10 @@
if (value.indexOf(basePath) == 0) {
value = value.substr(basePath.length);
}
if (/^[a-z][\w\/\. -]*$/i.test(value)) {
return value;
match = /^([a-z][\w\/\.\-+,]*?)(\?[\w &=+_,;-]+)?(#[\w_-]+)?$/i.exec(value);
if (match && match[1]) {
return match[1];
}
return false;
};
......@@ -71,11 +73,18 @@
if (!path) {
return false;
}
if (cache[path] !== undefined) {
return cache[path];
if (cache[value] !== undefined) {
return cache[value];
}
$.getJSON(Drupal.settings.ckeditor_link.revert_path + '/' + Drupal.encodePath(path), function(data) {
cache[path] = data;
var base = extractPath(data);
var pos = path.lastIndexOf(base);
var args = (pos != -1) ? value.substr(pos + base.length + 1) : '';
args = (args.charAt(0) == '/') ? args.substr(1) : args;
cache[value] = {
path: data,
args: args
};
callback();
});
};
......@@ -122,11 +131,7 @@
// Overrides linkType definition.
var infoTab = definition.getContents('info');
var content = getById(infoTab.elements, 'linkType');
content.items.unshift([Drupal.settings.ckeditor_link.type_name, 'drupal']);
infoTab.elements.push({
type: 'vbox',
id: 'drupalOptions',
children: [{
var elementChildren = [{
type: 'text',
id: 'drupal_path',
label: editor.lang.link.title,
......@@ -154,7 +159,32 @@
}
return true;
}
}]
}];
if (Drupal.settings.ckeditor_link.args_field) elementChildren.push({
type: 'text',
id: 'drupal_args',
label: Drupal.settings.ckeditor_link.path_args_label,
setup: function(data) {
this.setValue(data.drupal_args || '');
},
validate: function() {
var dialog = this.getDialog();
if (dialog.getValueOf('info', 'linkType') != 'drupal') {
return true;
}
if (!(/^([^\/][\w\/\.\-+,]+)?(\?[\w &=+_,;-]+)?(#[\w_-]+)?$/i.test(this.getValue()))) {
alert(Drupal.settings.ckeditor_link.msg_invalid_args);
this.focus();
return false;
}
return true;
}
});
content.items.unshift([Drupal.settings.ckeditor_link.type_name, 'drupal']);
infoTab.elements.push({
type: 'vbox',
id: 'drupalOptions',
children: elementChildren
});
content.onChange = CKEDITOR.tools.override(content.onChange, function(original) {
return function() {
......@@ -184,13 +214,14 @@
}
else if (data.url && !data.url.protocol && data.url.url) {
var dialog = this.getDialog();
var path = revertPath(data.url.url, function() {
var values = revertPath(data.url.url, function() {
dialog.setupContent(data);
resetInitValues(dialog);
});
if (path) {
if (values) {
data.type = 'drupal';
data.drupal_path = path;
data.drupal_path = values.path;
if (Drupal.settings.ckeditor_link.args_field) data.drupal_args = values.args;
delete data.url;
}
}
......@@ -203,7 +234,18 @@
data.type = 'url';
var dialog = this.getDialog();
dialog.setValueOf('info', 'protocol', '');
dialog.setValueOf('info', 'url', Drupal.settings.basePath + extractPath(dialog.getValueOf('info', 'drupal_path')));
var value = dialog.getValueOf('info', 'drupal_path');
var path = extractPath(value);
var args = Drupal.settings.ckeditor_link.args_field ? dialog.getValueOf('info', 'drupal_args') : '';
// Prepend a slash to args if required.
var fullArgs = (args && !(/^[\?#]/i.exec(args))) ? '/' + args : args;
var fullPath = Drupal.settings.basePath + path + fullArgs;
dialog.setValueOf('info', 'url', fullPath);
// Cache now to avoid a new lookup if only the args have changed.
cache[fullPath] = {
path: value,
args: args
}
}
};
});
......
Supports Markdown
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