I've set up an "image" CCK type. I have node reference fields on other content types that point to these image nodes, and I want to insert images from these other referenced nodes into the body of a node.

This patch adds additional styles for Insert widgets: node build modes and views that take a node ID argument. It has all kinds of little weird problems, so it's really presented for discussion and feedback.

What works:

1. I can refer to nodes and insert the rendered representations of them into the node body.
2. Any node reference widget can be used.

What doesn't work:

1. The insert behavior only works after the node reference field has been saved.
2. Multiple values and option and select widgets don't make any sense.

I'm posting this to Insert because it was relatively quick work to make Insert do this. However, this does break some of the fundamental concepts of Insert. Node references are not images or files, and Insert module assumes that we're working with files/images only. Styles can't be restricted to certain field types, so imagefield styles appear on node reference widget settings and vice versa.

Insert's javascript relies on a distinctive wrapper around the form element of the insertable item, and by default node reference widgets have no such wrapper. This patch adds this wrapper in a pretty clumsy way.

This may produce invalid HTML, too. If we can insert a full node into another node, the rendered node will need to be stashed in a hidden form element. Surely there are size limits to reckon with. If you enable many different insert styles for the widget, you're running views for each possibility, causing the node edit form to be very very heavy.

Why should the widget only support node IDs? I can pass a node ID value to a term ID views argument and handle all that with some custom argument validation.

Access and permissions are also problematic... the node or view is rendered using the current user's permissions. Users who are viewing the node where it's embedded in the body may not have permission to see that other node or view. If the user has "administer views" permission and the views admin links are enabled, these admin links are inserted into the node body as well. Probably this could be addressed with template preprocess functions on the views displays or by providing a views display plugin specifically for Insert style output.

CommentFileSizeAuthor
insert-nodereference.patch4.23 KBAnonymous (not verified)

Comments

looplog’s picture

I'd love to see some progress on this. A use case I have in mind is storing references to biblio nodes and inserting them as citations in the body text. If this patch can achieve this I'll be testing it out ASAP.

miro_dietiker’s picture

interesting. subscribe..

einkahumor’s picture

Very interesting. Another use case is to simply add node titles as links into the body text. This way users can create internal links using autocomplete and without having to lookup and copy-paste urls. Is there another (perhaps even better) way to do this?

looplog’s picture

I've built a rough version of insert with nodereference support that simply adds support for inserting the reference as a link. I'll try to post the code sometime over the next couple of days if I get a chance to roll a patch. Otherwise, I can pass on my undoubtedly shoddy code if anyone is interested.

einkahumor’s picture

I'd love to see a patch if you have time, thanks.

Anonymous’s picture

I'm keen to see your work, omjn.

For everyone else: the patch I made is going nowhere. I don't have time to contribute to Insert right now. I posted it here for education and discussion. But if anyone else wants to pick it up and run with it, I'm ready to review.

looplog’s picture

I had a look over my attempt yesterday and it's really rough. I did use some of bangpound's code and modified it to my needs but I couldn't work out how to use template_preprocess in the way the other handlers in insert do. Hence, the link classes are hardcoded for my purposes at the moment and completely ignore the insert settings. In short, it's very hackish. I'll try to fix it a little over the weekend if I can, and if not, post the code as is.

Ivo.Radulovski’s picture

Hi people wouldn't it be the nicest duo when this module works with the nodereference explorer? So Images can be reused that are already uploaded, can be easy searched trough the node reference explorer, easy uploaded and now easy inserted inline....

This would be one of the best image handling solutions for uploading, reusing, and displaying images !

scottrigby’s picture

@segments -- nodereference explorer is a sweet module... and agree together with Insert this would be an amazing combination

mrfelton’s picture

definitely subscribing :)

andyf’s picture

subscribe!

aac’s picture

Subscribing!!

quicksketch’s picture

riisi’s picture

subscribing

mbria’s picture

subscribe !!!

figjamalba’s picture

subscribe :-)

varac’s picture

Subscribing