I am desperately trying to embed a linodef tag using WYSIWYG TinyMCE button and I cannot get it to format correctly. The final tag I want in the editor is:

[#view_name,type="view",display="block_1",arguments="node_id"]

In my case this is:

[#emb_audio,type="view",display="block_1",arguments="188"]

When the custom TinyMCE button is clicked I would like it to show a list of all audio nodes (selected by view or node type; whichever is easier). When the user selects one it inserts the tag mentioned above and passes the argument node_id (in this example - 188).

Is this possible?

I have tried creating various taglists but can only pass the node id 188 as a hard coded argument.

Any help would be greatly appreciated.

Comments

tinker’s picture

I managed to get this to work by hacking the taglist.load.inc but I don't like hacking modules so I would like to request this as a feature and possibly help in developing it if you like. The current module is so close to working that it hurts and I think it would provide the missing link in embedding inline content.


Functionality

Let me start by describing the scenario for use.

  • Create an Audio Node which has a audio File Field that uses a CCK formatter to embed an audio player.
  • Create a View that performs two functions:
    • Lists all Audio Node Titles (Default)
    • Shows a block that displays the Audio Node Title and File Field (with player) when the Node ID is passed as an argument (Block_1)
  • Create a Linodef Taglist that selects a Node using the View
  • Linodef creates a button in my WYSIWYG editor
  • When the WYSIWYG button is clicked it displays the list of available nodes using the View
  • When a node is chosen Linodef inserts the Tag into the editor
  • This is the only new feature - Instead of creating a simple Node tag eg: [#188] it creates a Views Tag using the Source View but a different View Display and passes the Node ID as an argument eg: [#my_view,type="view",display="block_1",arguments="188"]
  • Linodef replaces the Tag and everything works


New Features

Like I said I have this working by hacking two lines of code but I would like to see this as an option in the Taglist Wizard. Here is what I propose:

On the Taglist Options & Properties page add a new fieldset "Tag format" which contains:

  • New checkbox "Use the Source View to format the display"
  • When enabled a dropdown list shows the available displays for the view
  • Add some text that say "The content ID will be passed to the view as an argument"


Benefits

I think this could revolutionize inline content filters for Drupal. It could provide better functionality for embedding content than all of the following modules: Inline, Image Assist, Audio Assist, Rep[lacement]Tags, and TinyMCE Node Picker.

  • Works with CCK Fields which is the better way of creating custom content
  • CCK handles the display of embedded players
  • Fully customizable listing of nodes to embed using Views
  • Fully customizable display of nodes using views
  • Can define viewing permissions for embedded content using Views


My temporary hack

// linodef/modules/linodef_taglists/includes/taglist.load.inc Line 34

function _linodef_taglists_getelementsbyviewname($viewname, $display_id = NULL, $args = NULL, $option_string, $tl_properties) {

	// EDIT - Use default display for select list and $display_id for display rendering
	// $view_result = _linodef_taglists_get_view_result($viewname, $display_id, $args);
	$view_result = _linodef_taglists_get_view_result($viewname, NULL, $args);
	// EDIT - Use default display for select list and $display_id for display rendering

	if (is_array($view_result)) {

		// Nodes/Fields.
		if (property_exists($view_result[0], nid)) {
			// Check for CCK fields: find the first field (lowest weight).
			$view_resultfields = get_object_vars($view_result[0]);
			while (current($view_resultfields) !== False && !$fieldvalue_key) {
				$view_resultkey = key($view_resultfields);
				if (substr($view_resultkey, 0, 15) == 'node_data_field') {
					// Create field name.
					$fieldname = strstr($view_resultkey, 'field_');
					$fieldname = substr($fieldname, 0, strrpos($fieldname, 'field_', 6)-1);
					// Key for the field value.
					if (substr($view_resultkey, -5) == 'value') {
						$fieldvalue_key = $view_resultkey;
					}
				}
				next($view_resultfields);
			}
			// Field syntax.
			if ($fieldvalue_key) {
				foreach ($view_result as $i => $item) {
					$item_vars = get_object_vars($item);
					if ($item_vars[$fieldvalue_key]) {
						$comment = _linodef_taglists_setdefaultcomment($tl_properties['comment'], $item_vars[$fieldvalue_key]);
						$output[$i] = array('tag' => '[#' . $item->nid .':'. $fieldname . $option_string . $comment . ']', 'desc' => $item_vars[$fieldvalue_key]);
					}
				}
			}
			// Default syntax (nodes).
			else {
				foreach ($view_result as $i => $item) {
					$node = node_load($item->nid);
					$comment = _linodef_taglists_setdefaultcomment($tl_properties['comment'], $node->title);

					// EDIT - Rewrite tag so that source view is used to display the node
					// $output[$i] = array('tag' => '[#' . $item->nid . $option_string . $comment . ']', 'desc' => $node->title);
					$output[$i] = array('tag' => '[#' . $viewname .',type="view",display="'. $display_id .'",arguments="'. $item->nid .'"' . $option_string . $comment . ']', 'desc' => $node->title);
					// EDIT - Rewrite tag so that source view is used to display the node

				}
			}
		}
// More code follows...


Please let me know if this is possible and if there is anything I could do to help in adding this functionality to the module.

Roi Danton’s picture

Title: WYSIWYG embed view with arguement » Allow alteration of tag format when using views
Component: WYSIWYG » Taglists
Category: support » feature
Priority: Minor » Normal

Thanks for your proposal and I'd like to discuss this further! Especially since the way taglists handles views is quite basic as it is now. Maybe when developing your solution we will detect some ways to solve #692520: Use rendered output of views, too. Currently I'm short on time for development but I'll try to answer your questions asap. The fieldset "Tag format" should be added in includes/admin.inc linodef_taglists_wizard_options_form.

Just one question: Why you've chosen to use a view with argument to embed the CCK field instead of the fieldname directly: [#nid,content="field_name"]. It is because filefield doesn't work yet properly with taglists: #703194: Add file/image/reference field support for taglists? Or is it primarily because you want to display the node (titles) in the taglists and not the field content itself?

Pepe Roni’s picture

I think, it could be the other way: #692520: Use rendered output of views will also be able to solve this issue :)

tinker’s picture

Yes I think that my request is similar to #69250. I am using the view with argument because I wish to see a fully rendered block that contains multiple fields. In my case is the content title linked to node and a MP3 file with embedded player.

Thanks for letting me know which file to look at. I will check it out and maybe create a patch if I understand it.