Hi,

Full disclosure: I am helping @StuartDH with his issue at #1839342: Paid Plugin Development (and I'm also coming into making this issues from #1072318: Linkit to insert images from image nodes).

I was able to get the title in the linkit picker to show an image + title text without any real issue but the part where I ran into larger issues was when I wanted to insert the title back into the WYSIWYG editor (in this case, I was using CKEditor). Instead of inserting something like <a href="http://example.com/node/1"><img src="http://example.com/example.jpg" />Test title</a>, it would add <code><a href="http://example.com/node/1>&lt;img src="http://example.com/example.jpg /&gt;Test title</a> which rendered it unusable. I could kind of use the insert plugin if wysiwyg was not enabled but that has its own set of issues for content editors. In looking through the code, I found that by editing (ckeditor/plugin.js so far) from:

var text = new CKEDITOR.dom.text(Drupal.linkitCache.link_tmp_title, editor.document);

to

var text = new CKEDITOR.dom.element.createFromHtml(Drupal.linkitCache.link_tmp_title, editor.document);

I am able to add rich text without issue (the image or any other html output I want shows up really well). However, I can understand where something like this might not be favourable. So I am wondering if the output of linkit resultsets can include one more attribute: 'html'. So if a plugin chooses to, it could instead return:

      $matches[] = array(
        'title' => $this->buildLabel($entity),
        'description' => $this->buildDescription($entity),
        'path' => $this->buildPath($entity),
        'group' => $this->buildGroup($entity),
        'addClass' => $this->buildRowClass($entity),
        'html' => TRUE,
      );

Where 'html' implies that the content that needs to be rendered contains html. Thus, the linkitcache in the js could just do a check like (atleast for ckeditor)

if (Drupal.linkitCache.html == true) {
  var text = new CKEDITOR.dom.element.createFromHtml(Drupal.linkitCache.link_tmp_title, editor.document);
}
else {
  var text = new CKEDITOR.dom.text(Drupal.linkitCache.link_tmp_title, editor.document);
}

Thus retaining the functionality to the way it has been in linkit core. I am happy to write out the patch in full (I'll need to research tinymce on how it inserts content but ckeditor is pretty much resolved) for review so we can test and make sure this works if this sounds like a reasonable approach.

CommentFileSizeAuthor
#3 1846502.patch2.62 KBBTMash
#2 1846502.1.patch2.26 KBBTMash
#1 1846502.patch2.32 KBBTMash
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BTMash’s picture

Status: Active » Needs review
FileSize
2.32 KB

This is a first stab at a patch. I know new features should be going into 3.x but putting it here since the client I'm doing this for is using the stable 2.x (and I'll forward-port this to 3.x) version of the module. This currently works with the CKEditor plugin and thus the plugin needs to be extended to also work with TinyMCE. But the core of it is to be able to add a 'is_html' attribute to the resultset that can then be used by any wysiwyg editor. Unless another plugin sets that attribute, everything should work as it has been so far (in which case, the rich html version is output instead).

Even though I know this needs work, setting to needs review for any additional feedback.

BTMash’s picture

FileSize
2.26 KB

Coming back to this patch as there have been numerous changes since the issue was filed.

Adding a new linkit function isHTML which determines if the output can be rendered as html.

BTMash’s picture

FileSize
2.62 KB

Sorry, wrong version of patch.

BTMash’s picture

Issue summary: View changes

Updated issue summary.

anon’s picture

Status: Needs review » Closed (won't fix)

Closing this as 7.x-2.x is not developed any more and will soon not be maintained.