TinyMCE link list problem

I am using TinyMCE as my default WYSIWYG editor in my CMS for some time, but I was facing problems with implementation custom link list in dialogs every now and then so I finally put together working solution.

The documentation


I was always angry on TinyMCE's documentation policy, it is really brief and totally ignores or avoids the possibility that it's just not enough. I've found documentation for my problem of course, but guess what .. Didn't work. Here's my "source" - TinyMCE documentation for the custom link list implementation.

The problem


So where's the problem ?? I've set the external_link_list_url attribute, created the list file, and the result was nothing. Nothing showed in my dialogs. You have to add the advlink plugin to the list of your TinyMCE plugins, but that didn't help. Perhaps the problem was that I generated the list file by script, but I've tried static list too, didn't work either. The static list was of course not an option for me, I needed to generate it.

The solution


The solution was to put the same code that generated the list file in this file, make this file .php and edit the external_link_list_url attribute to this php file. You have to echo your generated content in this php file of course. And voila, it works. Here's an example of how your link_list.php file can look like:

$links  = array();
 
$query  = 'SELECT `text`,`link` FROM `your_table`';
$result = $db->Query($query);
while ($row = mysql_fetch_object($result))
{
    $links[] = '["'.$row->text.'","'.$row->link.'"]';
}//while
 
$cont  = implode(','."\r\n",$links);
 
$cont  = 'var tinyMCELinkList = new Array('."\r\n".$cont."\r\n".');';
 
echo $cont;


I used a simple db query for this example, you can use any custom loop to generate your links array.

This is the whole solution, it works perfectly for me, hope it helps.