I have a database table that I have populated directly with HTML code (like link).

I import the table into TW, analyse it and create the default View.

However, when I view the table contents (either using the default View that TW created, or a custom View), the HTML has been converted to entities (> etc) even tho I have not specified anywhere that it should be.

Am I misunderstanding the process? The SQL being generated is fine (it returns the raw HTML as expected) but the View in encoded. This also means the "strip HTML" checkbox in the Field option is useless since the tags are no longer tags!

Please help - not being able to include HTML in my source tables makes this very difficult to use.

Thanks for the support!

CommentFileSizeAuthor
#13 tw-handler_select-770472.patch7.36 KBwapnik
#10 tw.patch925 byteswapnik
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

palpatine1976’s picture

Sorry - text above wasn't clear. The contents of the source database table is like:

<a href="http://www.example.com" rel="nofollow">link</a>.

But the View converts the HTML to entities, so < becomes &lt; etc.

I need the HTML unchanged so that links etc. actually work in the View!

palpatine1976’s picture

I know that I could theme the output of a specific field by creating a views--view--FIELDNAME.tpl.php file for EACH field I want to output raw data, but surely there could be an internal hook set in TW that tells Views to allow Full HTML for that field? Maybe a content type checkbox on the admin screen (next to where you choose to Ignore fields?)

palpatine1976’s picture

Bump...

mikeryan’s picture

Category: bug » feature

Views does, I believe, do a check_plain on text fields by default, and that seems prudent to me. The ability to use Table Wizard to override this behavior would be a new feature.

palpatine1976’s picture

Hi Mike -

Thanks for the reply.

Yeah I think this would be a feature request (not a bug) but still would be really handy; it would allow the inclusion of HTML directly from a TW-linked db table. Obviously care would need to be taken on the admin side to cleanse/validate the HTML in the db table, but if the option were available to choose Text or Full HTML in the schema options in TW, it wouldn't be any different to choosing an Input Format when editing a page.

For example, if you make a custom Content Type using CCK fields, you can include HTML in them and it will be rendered (not encoded) in Views. Clearly there is a way to tell Views on a field-level basis "leave the HTML alone in this field" - and to be able to control that likewise in TW would be great!

However I don't have an idea of the LoE for this - I'm sure it could be trickier than it seems.

palpatine1976’s picture

I really can't believe NO-ONE out there has HTML in external database tables that they wish to bring in to a Drupal View and display as-is. How are other people doing it?

ajspadial’s picture

I have also the same problem.

And I neither know how to make a template that render my html field as palpatine1976 sais in #2. I would be glad to see an example.

I've tried with

  print $row->{field->field_alias};

But i get "an error ocurred at " in my navigator (firefox)

palpatine1976’s picture

Since no-one else has commented on this, and it doesn't look like it's going to make it as a feature (tho I really think it should) I developed a work-around.

1) Create a theme_preprocess function in your template.php file for the function that renders the view fields:

function YOURTHEME_preprocess_views_view_field(&$variables) {
	// Create new variable $outputHTML for each field
	$variables['outputHTML'] = filter_xss_admin($variables['row']->{$variables['field']->field_alias});
}

2) Modify the display by creating a views-view-field.tpl.php file in your theme

	$viewTag = $view->tag;
	$fieldName = $field->options['field'];

	if (($viewTag=='tw') && (strpos($fieldName, 'HTML_') === 0)) {
		print $outputHTML;
	}
	else {
		print $output;
	};
	unset($viewTag, $fieldName);

This basically says:
"If this field is coming from a view tagged "tw" (TableWizard) AND column name in the db starts with the string "HTML_" then use the HTML output instead of the encoded default output.

As you can see, my HTML output uses filter_xss_admin() to strip out any script or style tags, but leaves everything else. You could modify this to be stricter, or make several different vars available for display.

Hope this helps some people out! Comments/improvements welcome.

Goz

mikeryan’s picture

Status: Active » Closed (won't fix)

I don't think rendering HTML within a table is as common a scenario as you're imaging - stripping or encoding HTML tags will be the right thing 99% of the time in practice.

Table Wizard is being deprecated in favor of the Data module - and you can achieve what you want with that module. After "adopting" the table into data, under the "Configure views" tab change the handler for your HTML-containing field to views_handler_field_data_markup. Then, edit the view, select the field, and choose the Full HTML format.

wapnik’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Closed (won't fix) » Needs review
FileSize
925 bytes

I allowed myself to open this issue once again.

Table wizard can make a good use of views_handler_field_markup handler which is not encoding html entities on rendering like views_handler_field does, but instead, it applies drupal filters on it. This also solves the same problem, that we have in Migrate module in #474618, which is blocking us from rendering the data in the view before migrating.

This patch is now using the default drupal filter. If necessary, i can provide some radio button for setting which filter to use. Or a radio button next to every relevant field...

palpatine1976’s picture

@wapnik - this is awesome! Such a nice simple solution - now I can import and display HTML without needing to write tpl.php files. I hope this patch will get rolled into a release - even tho TW is being depricated for the Data module, this would be a worthy minor release IMHO.

Thanks again.

mikeryan’s picture

Status: Needs review » Needs work

I don't believe the markup filter should be the default, there needs to be a means to select it only when needed.

wapnik’s picture

Status: Needs work » Needs review
FileSize
7.36 KB

A select for every field provided. Markup handler as default makes sense after issue #474618 is commited. Views provided field rewriting can be used then which i think is very useful.

pthanos’s picture

I too am very intersted in importing HTML data.

I am trying to apply the above patches to the latest versions of table wizard. The latest patch makes my tw module produce blank pages.. Is there an update on this issue?

wapnik’s picture

it seems to work for me
this patch is against 6.x.1.x-dev maybe you're using different version
where exactly do you see blank pages..and can you provide some php error messages?

pthanos’s picture

Apologies for practically spamming the thread without posting any specific details. In the end I moved to the Data module, which helped me accomplish what I needed. Data provides the views that migrate can use to create nodes etc.

palpatine1976’s picture

@wapnik I just updated my TW to the latest 6.x.1.x-dev build (2010-Nov-12), and applying the patch #13 white-screens any page using TW on my site too. Looks like a fatal error since no PHP errors are returned to screen.

Maybe this only occurs if you have existing TW definitions prior to the patch, and there is some conflict between existing settings and the new UI?

Shai’s picture

@palpatine1976, thank you so much for this great snippet!