I have a view that outputs a list of nodes for a menu. The view displays the title linked to the node. The View allows published nodes or nodes in the moderations states draft or review. How can I add a class around the titles that are in draft or review. I would like to style these differently. I am using drupal_view to print the block inside a template. Can this be done in a theme preprocess or custom module?
This can be done through the Views interface.
You can add classes based on existing Field values to entire rows in
Format > Settings, or you can add classes to individual Fields (you mentioned title) under
Style settings wrapper or field HTML options.
Tokens to use in all of these cases can be found in the settings of the Field according to which you want to style the rows/other fields. The settings are under
Rewrite results > Override the output of this field with custom text > Replacement patterns options.
You don't have to actually keep the rewrite enabled, you just need to temporarily reveal and uncollapse to copy the tokens you need.
Then add CSS for those classes to your subtheme as usual, or through CSS editor module. You can hide the field ("Exclude from display") but it needs to be there on the list, arranged before any other fields that may use its value for classes.