Views 2: Remove   and markup from field rendering

mariagwyn - August 21, 2009 - 01:06
Project:Taxonomy Lineage
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

It appears that the module is working in that the heading of the sub-term is indented. However, it is indented via lineage_handler_field.inc, at line 20:

    // output pseudo-link (without href) with hierarchically indented term and full path via title/alt-rollover
    return str_repeat('   ', substr_count($content, "\n")-1)
           . '<a title="' . $s . '" alt="' . $s . '">' . $a . '</a>';

Using &nbsp does not allow for any unique styling to sub-terms. I would like to output CSS, along these lines:

    // output sub-term as title with span class for CSS modification
    return str_repeat('', substr_count($content, "\n")-1)
    . '<span class="term-level-#">' . $a . '</span>';

Where "#" is the level of the term (1, 2, 3). This allows me to style this term via CSS.

It appears that the field handler is removing the depth of the term. I cannot figure out how to get the level in the code.

Any help on this?

maria

#1

mariagwyn - August 26, 2009 - 21:26

any suggestions or help on this? It would be a very helpful addition to this module since using '&nbsp' offers no styling options.

#2

xjm - October 21, 2009 - 17:07

Tracking. The oodles of &nbsp; mostly get in the way and seem to interfere with the sorting order when sorting by hierarchy. Wouldn't it make more sense with Views 2 to simply include the raw lineage, with no markup, and then let the user override the markup as appropriate?

mariagwyn: I think you want to take a look at adding a Term: Depth field in your view. Add this field, but exclude it from display, and you can use it with the "Rewrite the output of this field" checkbox for another field. This will give you a number you can then use in your CSS. E.g., you might have fields:

Node: Title
Taxonomy: Depth
Taxonomy: Term

You'd check "Exclude from display" for the term depth and "Rewrite output" for the term, using something like the following override template:
<span class="term-level-[depth]">[name]</span>

(Note that "name" is the default token for the taxonomy term.)

#3

xjm - October 21, 2009 - 16:48
Title:Use CSS to style term level outputs» Views 2: Remove &nbsp; and markup from field rendering
Version:6.x-1.0» 6.x-1.x-dev
Category:support request» feature request

Marking as feature request.

#4

mariagwyn - October 21, 2009 - 20:38

I ended up solving the problem with views in much the same way xjm suggested. It required a patch however, since the views 'group-by' was not allowing me to style the field using tokens. See: http://drupal.org/node/502348#comment-2155496

It is a worthy feature request here so that this module can be more effective on its own.

#5

xjm - October 22, 2009 - 23:01
Status:active» needs work

This patch adds a primitive formatting option form so that the user can select either the raw (linebreak-delimited) format for the lineage (presumably for use in a custom style plugin), or the original "pseudo-link" format that's been used to date. It will default to the original format if the format is undefined, so that there's not unexpected results with views created prior to applying this patch.

I'm marking this "needs work" because it would be more useful to have a more sophisticated formatting form with options like:

[ ] Strip weights
[ ] Machine-safe (for CSS class names, etc.)

Term prefix: ______________ (append before each term name in the lineage)
Term suffix: ______________ (append after each term name in the lineage)
Delimiter between terms: __________ (use \n for line breaks)

Note that #507472: Fix weight string handling for D6 is relevant to this as well.

AttachmentSize
lineage_6_1-dev_format_options.patch 2.44 KB

#6

xjm - October 22, 2009 - 23:00

Patch with proper naming convention, sorry for double post.

AttachmentSize
lineage_6_1-dev_555316_6.patch 2.44 KB

#7

xjm - October 28, 2009 - 17:21

This version of the patch should work with patch in #3 in #507472: Fix weight string handling for D6.

AttachmentSize
lineage_6_1-555316-7.patch 2.46 KB
 
 

Drupal is a registered trademark of Dries Buytaert.