I'm sorry if this has already been answered, however I have searched this knowledge base and I have found articles that are the same as my problem, the only thing is, the solutions that have been identified, don't seem to work with my installation.

I have created a content type and I am trying to theme for that content type. I have created a node template file for the content type and have used the following line:-

<?php print content_format('field_bookhotelnowlink', $field_bookhotelnowlink[0], 'default', $node) ; ?>

When I call a node with this content type as an anonymous user, one of the fields is returned as n/a. The field in question is used by the admin to enter some HTML to create a button on content that is created by a registered user.

Any ideas or help would be gratefully appreciated.

CommentFileSizeAuthor
#7 cck-text-na-435520.patch674 bytesyched

Comments

yched’s picture

Looks like check_markup ends up being called with $check param = TRUE.
text_field('sanitize') has :

$check = is_null($node) || (isset($node->build_mode) && $node->build_mode == NODE_BUILD_PREVIEW);
$text = isset($item['value']) ? check_markup($item['value'], $item['format'], $check) : '';

I don't actually remember why we have this $check code, but since you're providing a $node to content_format().

Not much time to investigate right now, but you could try drirectly printing $field_bookhotelnowlink[0]['view'] instead.
Or use the $field_bookhotelnowlink_rendered variable, that contains the whole output for the field (including label and multiple values)

tsredman’s picture

Status: Active » Closed (fixed)

Fantastic!!! Thank you very much for your help. That works a charm.

yched’s picture

Status: Closed (fixed) » Active

Reopening + marked #458204: content_format() with text areas returns "n/a" if user doesn't have permission to use input format as duplicate.

As I said above, I see no reason why text_field($op = 'sanitize') should bother calling check_markup() with $check = TRUE when the node is being previewed.

I kind of vaguely remember mirroring this code after some core case (node body ?), which might have changed meanwhile. In current D6 core, node module doesn't bother with anything, and always renders the body with $check = FALSE.

The only core check_markup($check = TRUE) call in core is when generating a comment title out of a comment body (http://api.drupal.org/api/function/_comment_form_submit/6). Not even true in D7 anymore, since the $check param has been removed completely, and the corresponding code in http://api.drupal.org/api/function/comment_form_submit/7 calls a regular check_plain() without any format access check.

Pinging sun, which should have more accurate ideas than mine on this topic, but it looks like we could remove the $check param from that check_markup() call.

sun’s picture

Category: support » bug

The $check parameter is an old construct of pre-Form API times, in which not validated submitted form values were used to render a preview. The preview was generated during form processing/validation, so user access to the selected text format was not validated/verified/secured. $check had to be TRUE mainly for those invocations. Since no preview is generated in case of a form validation error today, the $check parameter is basically obsolete and therefore has been removed from D7: #446518: Remove $check argument from check_markup()

$check should always be FALSE when rendering a stored piece of text with an assigned text format, which has been properly validated before storage.

The only exceptions for passing $check = TRUE are:

1) when displaying a preview AND short-circuiting Form API validation. (i.e., rendering a preview despite a form validation error)

2) when filtering a text using an arbitrary format. This usage is completely wrong and bogus in the first place. The only location where this happens is for rendering text fields of Profile module in core, since Profile module does not store any text format for the field value.

eric_a’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Priority: Normal » Major

This a really terrible...

yched’s picture

Status: Active » Fixed
StatusFileSize
new674 bytes

Finally fixed - committed the attached patch to both 2.x and 3.x branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.