Created
January 27, 2015 15:09
-
-
Save vdchristelle/812e10ceecfc9d170f99 to your computer and use it in GitHub Desktop.
Adding node type and node id to the link field in WYSIWYG.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------------------------------------- | |
//------------- CKEDITOR ----------------- | |
//---------------------------------------- | |
/* | |
* alter cklink to add language | |
*/ | |
function YOUR_MODULE_ckeditor_link_autocomplete_alter(&$results, &$string){ | |
if ($string !== '') { | |
$types = ckeditor_link_get_types(); | |
$results = array(); | |
foreach ($types as $type) { | |
$func = $type['module'] .'_ckeditor_link_'. $type['type'] .'_autocomplete'; | |
if($type['type']=="node"){ | |
$func="ckeditor_link_ckeditor_link_node_autocomplete_custom"; | |
} | |
if (function_exists($func)) { | |
$results += $func($string); | |
if (count($results) > 10) { | |
break; | |
} | |
} | |
} | |
} | |
} | |
function ckeditor_link_ckeditor_link_node_autocomplete_custom($string) { | |
$matches = array(); | |
$node_types = array_keys(array_filter(variable_get('ckeditor_link_autocomplete_node_types', array('- any -' => '- any -')))); | |
if (count($node_types)) { | |
//we assume i18n is enabled | |
global $language; | |
$db_or = db_or(); | |
$db_or->condition('n.language', 'und'); | |
$db_or->condition('n.language', $language->language); | |
$query = db_select('node', 'n') | |
->fields('n', array('nid', 'title','language')) | |
->condition('n.title', '%'. db_like($string) .'%', 'LIKE') | |
->condition($db_or) | |
->orderBy('n.title') | |
->orderBy('n.type') | |
->range(0, 10) | |
->addTag('node_access'); | |
if (!in_array('- any -', $node_types)) { | |
$query->condition('n.type', $node_types, 'IN'); | |
} | |
$result = $query->execute(); | |
foreach ($result as $node) { | |
$matches['node/'. $node->nid] = "TAAL:".$node->language." ".drupal_get_path_alias("node/".$node->nid); | |
} | |
} | |
return $matches; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment