How do I use a preprocess function to add custom classes to a view fields? I have a View that outputs several fields per row. I'd like to use a preprocess function to add a class to one of the fields, depending on the value of another field. How do I do that in Drupal 8?

Note, I do not want to add a class to the entire row -- just a specific field in that row. The output would be something like:

&lt;div class="views-row"&gt;
  &lt;div class="views-field field-name-a"&gt; ... &lt;/div&gt;
  &lt;div class="views-field field-name-b has-custom-class"&gt; ... &lt;/div&gt;
&lt;/div&gt;
As mentioned in the comment you can add classes to fields through the interface, and you can use field tokens as CSS classes. 

Add field-value-based CSS class to a field


Position the field with the value you want to use as the CSS class (the value-class field) above the field where you want the class to appear (the styled field). 
Set the value-class field to Exclude from display if you don't want it to appear there. 

If you need it visible in some other place then add that same field again where you need it, while keeping the first one for the token (because you can only use tokens of fields preceding in the Fields list).  
Edit the field where you want to apply the CSS class (the styled field) > 


Uncollapse Style settings > 
Customize field and label wrapper HTML (or Customize field HTML if you don't need the wrapper) > 
Create a CSS class and 
enter the first part of your class (myclass)  

(class names can't start with numbers and some special characters so it's good to control at least the first character to make it independent of the other field's value to prevent trouble down the line). 

Uncollapse Rewrite results (don't enable it, you just need to temporarily reveal and uncollapse to copy the token), 


uncollapse Replacement patterns, 
copy the value-class field token and 
paste it in the above CSS class field 

(you end up with something like myclass-[field_name_a]).  

Save the View and check your HTML output (in any theme), you will see a class based on your value-class field on the field where you added the class, something like class="views-field views-field-name-b myclass-namebvalue".