Categories
CMS Drupal Mastering Development

How do I inject css classes to a rendered field with a view style?

I maintain a module that provides several views styles. I have been unable to figure out how to get the fields where a users custom css entered in the views UI is then output with the view when I have to use style_plugin->getField (Drupal 8) or style_plugin->get_field (Drupal 7). It returns a "rendered" field, but that rendering does not include css additions added in the view settings. Secondarily, I’d like to inject some css classes for some of those fields (img styles added as a class to the img tag) but can’t seem to figure that one out. I don’t know of a function from views that would return a render array instead of the rendered output. I’m not sure what I’m missing.

Here is the Views UI:
enter image description here

This css class "hello-world-field" is not in the output code at all.

Leave a Reply

Your email address will not be published. Required fields are marked *